Source for file Chain.php

Documentation is available at Chain.php

  1. <?php
  2. /*
  3.  *  $Id$
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information, see
  19.  * <http://www.phpdoctrine.com>.
  20.  */
  21.  
  22. /**
  23.  * Doctrine_Query_Filter_Chain
  24.  *
  25.  * @package     Doctrine
  26.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  27.  * @category    Object Relational Mapping
  28.  * @link        www.phpdoctrine.com
  29.  * @since       1.0
  30.  * @version     $Revision$
  31.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  32.  */
  33. {
  34.     /**
  35.      * @var array $_filters         an array of Doctrine_Query_Filter objects
  36.      */
  37.     protected $_filters = array();
  38.     /**
  39.      * add
  40.      *
  41.      * @param Doctrine_Query_Filter $filter 
  42.      * @return void 
  43.      */
  44.     public function add(Doctrine_Query_Filter $filter)
  45.     {
  46.         $this->_filters[$filter;
  47.     }
  48.     /**
  49.      * returns a Doctrine_Query_Filter on success
  50.      * and null on failure
  51.      *
  52.      * @param mixed $key 
  53.      * @return mixed 
  54.      */
  55.     public function get($key)
  56.     {
  57.         if isset($this->_filters[$key])) {
  58.             throw new Doctrine_Query_Exception('Unknown filter ' $key);
  59.         }
  60.         return $this->_filters[$key];
  61.     }
  62.     /**
  63.      * set
  64.      *
  65.      * @param mixed $key 
  66.      * @param Doctrine_Query_Filter $listener 
  67.      * @return void 
  68.      */
  69.     public function set($keyDoctrine_Query_Filter $listener)
  70.     {
  71.         $this->_filters[$key$listener;
  72.     }
  73.     /**
  74.      * preQuery
  75.      *
  76.      * Method for listening the preQuery method of Doctrine_Query and
  77.      * hooking into the query building procedure, doing any custom / specialized
  78.      * query building procedures that are neccessary.
  79.      *
  80.      * @return void 
  81.      */
  82.     public function preQuery(Doctrine_Query $query)
  83.     {
  84.         foreach ($this->_filters as $filter{
  85.             $filter->preQuery($query);
  86.         }
  87.     }
  88.     /**
  89.      * postQuery
  90.      *
  91.      * Method for listening the postQuery method of Doctrine_Query and
  92.      * to hook into the query building procedure, doing any custom / specialized
  93.      * post query procedures (for example logging) that are neccessary.
  94.      *
  95.      * @return void 
  96.      */
  97.     public function postQuery(Doctrine_Query $query)
  98.     {
  99.         foreach ($this->_filters as $filter{
  100.             $filter->postQuery($query);
  101.         }
  102.     }
  103. }