I'm writing some code which acts as a search component, returning primary keys for later use inside our application. Currently all "filters" on are hard-coded into the search class. These are effectively just bare comparisions against field values:
Pseudo:
Code: Select all
$search = new SearchCriteria();
$search->setFieldOne('some value');
$search->setAnotherField('some other value');
var_dump($search->getPks()); //Primary keys
This works beautifully except it's now growing beyond a maintainable size and we also want to create a view helper using this as a model. I've taken the decision to refector the search object into a central class, with loosely coupled strategies attached.
Code: Select all
$search = new SearchComponent();
$search->addStrategy(new DateStrategy('some date'));
For the "View" components there's another layer sitting on top, but this is irrelevant right now.
The problem I'm facing right now is that each strategy needs to be able to access a SQL query which is being manufactured inside the central component. The strategy should then be able to add an tables it needs to a SELECT query, along with any search conditions in the WHERE clause. Passing a string is going to have me jumping through hoops so I was hoping to pass around a nice "Query Builder" object with some ORM type of methods like
Code: Select all
$q->addTable('table1');
$q->addTable('table2');
$q->addCriteria('table1.somefield', 'some value', Builder::EQUAL);
echo $q->getSql();
Does anyone know of something like this which is up to date? So far I've found only one class on PHPClasses.org but I can't stand the site and I've never had a great deal of success getting good code from there. I have started writing my own but don't really want to re-invent the wheel
