I'm trying to find out what the best way would be to have a specification pattern in PHP where the specifications could (optionally) by transformed to PHP.
I am exploring some new directions and am testing how well they would work. Code and ideas are still very unclear in my mind.
Minimal interfaces would be like these:
interface IRepository {
public function get(ISpecification $specification);
}
interface ISpecification {
public function isSatisfiedBy($candidate);
}
If the repository hides a sql database the specification would need to transform to sql. Adding a ->toSQL() method seems ad hoc. A class that translates the specifications is also an option but it seems like a lot of overhead to finally generate the sql.
Ideas appreciated.