diff --git a/lib/Doctrine/Query/Filter.php b/lib/Doctrine/Query/Filter.php new file mode 100644 index 000000000..95d2e884c --- /dev/null +++ b/lib/Doctrine/Query/Filter.php @@ -0,0 +1,61 @@ +. + */ + +/** + * Doctrine_Query_Filter + * + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + * @author Konsta Vesterinen + */ +class Doctrine_Query_Filter implements Doctrine_Query_Filter_Interface +{ + /** + * preQuery + * + * Method for listening the preQuery method of Doctrine_Query and + * hooking into the query building procedure, doing any custom / specialized + * query building procedures that are neccessary. + * + * @return void + */ + public function preQuery(Doctrine_Query $query) + { + + } + /** + * postQuery + * + * Method for listening the postQuery method of Doctrine_Query and + * to hook into the query building procedure, doing any custom / specialized + * post query procedures (for example logging) that are neccessary. + * + * @return void + */ + public function postQuery(Doctrine_Query $query) + { + + } +} diff --git a/lib/Doctrine/Query/Filter/Chain.php b/lib/Doctrine/Query/Filter/Chain.php new file mode 100644 index 000000000..f5a0e532b --- /dev/null +++ b/lib/Doctrine/Query/Filter/Chain.php @@ -0,0 +1,104 @@ +. + */ + +/** + * Doctrine_Query_Filter_Chain + * + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + * @author Konsta Vesterinen + */ +class Doctrine_Query_Filter_Chain +{ + /** + * @var array $_filters an array of Doctrine_Query_Filter objects + */ + protected $_filters = array(); + /** + * add + * + * @param Doctrine_Query_Filter $filter + * @return void + */ + public function add(Doctrine_Query_Filter $filter) + { + $this->_filters[] = $filter; + } + /** + * returns a Doctrine_Query_Filter on success + * and null on failure + * + * @param mixed $key + * @return mixed + */ + public function get($key) + { + if ( ! isset($this->_filters[$key])) { + throw new Doctrine_Query_Exception('Unknown filter ' . $key); + } + return $this->_filters[$key]; + } + /** + * set + * + * @param mixed $key + * @param Doctrine_Query_Filter $listener + * @return void + */ + public function set($key, Doctrine_Query_Filter $listener) + { + $this->_filters[$key] = $listener; + } + /** + * preQuery + * + * Method for listening the preQuery method of Doctrine_Query and + * hooking into the query building procedure, doing any custom / specialized + * query building procedures that are neccessary. + * + * @return void + */ + public function preQuery(Doctrine_Query $query) + { + foreach ($this->_filters as $filter) { + $filter->preQuery($query); + } + } + /** + * postQuery + * + * Method for listening the postQuery method of Doctrine_Query and + * to hook into the query building procedure, doing any custom / specialized + * post query procedures (for example logging) that are neccessary. + * + * @return void + */ + public function postQuery(Doctrine_Query $query) + { + foreach ($this->_filters as $filter) { + $filter->postQuery($query); + } + } +} diff --git a/lib/Doctrine/Query/Filter/Interface.php b/lib/Doctrine/Query/Filter/Interface.php new file mode 100644 index 000000000..4ad8e22ec --- /dev/null +++ b/lib/Doctrine/Query/Filter/Interface.php @@ -0,0 +1,57 @@ +. + */ + +/** + * Doctrine_Query_Filter_Interface + * + * @package Doctrine + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + * @author Konsta Vesterinen + */ +interface Doctrine_Query_Filter_Interface +{ + + /** + * preQuery + * + * Method for listening the preQuery method of Doctrine_Query and + * hooking into the query building procedure, doing any custom / specialized + * query building procedures that are neccessary. + * + * @return void + */ + public function preQuery(Doctrine_Query $query); + + /** + * postQuery + * + * Method for listening the postQuery method of Doctrine_Query and + * to hook into the query building procedure, doing any custom / specialized + * post query procedures (for example logging) that are neccessary. + * + * @return void + */ + public function postQuery(Doctrine_Query $query); +}