Source for file Chain.php

Documentation is available at Chain.php

  1. <?php
  2. /*
  3.  *  $Id: Chain.php 2186 2007-08-09 22:16:33Z jackbravo $
  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. Doctrine::autoload('Doctrine_Access');
  22.  
  23. /**
  24.  * Doctrine_EventListener_Chain
  25.  * this class represents a chain of different listeners,
  26.  * useful for having multiple listeners listening the events at the same time
  27.  *
  28.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  29.  * @package     Doctrine
  30.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  31.  * @category    Object Relational Mapping
  32.  * @link        www.phpdoctrine.com
  33.  * @since       1.0
  34.  * @version     $Revision: 2186 $
  35.  */
  36. {
  37.     /**
  38.      * @var array $listeners        an array containing all listeners
  39.      */
  40.     private $listeners = array();
  41.     /**
  42.      * add
  43.      * adds a listener to the chain of listeners
  44.      *
  45.      * @param object $listener 
  46.      * @param string $name 
  47.      * @return void 
  48.      */
  49.     public function add($listener$name null)
  50.     {
  51.         if ($listener instanceof Doctrine_EventListener_Interface&&
  52.              ($listener instanceof Doctrine_Overloadable)) {
  53.             
  54.             throw new Doctrine_EventListener_Exception("Couldn't add eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
  55.         }
  56.         if ($name === null{
  57.             $this->listeners[$listener;
  58.         else {
  59.             $this->listeners[$name$listener;
  60.         }
  61.     }
  62.     /**
  63.      * returns a Doctrine_EventListener on success
  64.      * and null on failure
  65.      *
  66.      * @param mixed $key 
  67.      * @return mixed 
  68.      */
  69.     public function get($key)
  70.     {
  71.         if isset($this->listeners[$key])) {
  72.             return null;
  73.         }
  74.         return $this->listeners[$key];
  75.     }
  76.     /**
  77.      * set
  78.      *
  79.      * @param mixed $key 
  80.      * @param Doctrine_EventListener $listener 
  81.      * @return void 
  82.      */
  83.     public function set($keyDoctrine_EventListener $listener)
  84.     {
  85.         $this->listeners[$key$listener;
  86.     }
  87.     /**
  88.      * onLoad
  89.      * an event invoked when Doctrine_Record is being loaded from database
  90.      *
  91.      * @param Doctrine_Record $record 
  92.      * @return void 
  93.      */
  94.     public function onLoad(Doctrine_Record $record)
  95.     {
  96.         foreach ($this->listeners as $listener{
  97.             $listener->onLoad($record);
  98.         }
  99.     }
  100.     /**
  101.      * onPreLoad
  102.      * an event invoked when Doctrine_Record is being loaded
  103.      * from database but not yet initialized
  104.      *
  105.      * @param Doctrine_Record $record 
  106.      * @return void 
  107.      */
  108.     public function onPreLoad(Doctrine_Record $record)
  109.     {
  110.         foreach ($this->listeners as $listener{
  111.             $listener->onPreLoad($record);
  112.         }
  113.     }
  114.     /**
  115.      * onSleep
  116.      * an event invoked when Doctrine_Record is serialized
  117.      *
  118.      * @param Doctrine_Record $record 
  119.      * @return void 
  120.      */
  121.     public function onSleep(Doctrine_Record $record)
  122.     {
  123.         foreach ($this->listeners as $listener{
  124.             $listener->onSleep($record);
  125.         }
  126.     }
  127.     /**
  128.      * onWakeUp
  129.      * an event invoked when Doctrine_Record is unserialized
  130.      *
  131.      * @param Doctrine_Record $record 
  132.      * @return void 
  133.      */
  134.     public function onWakeUp(Doctrine_Record $record)
  135.     {
  136.         foreach ($this->listeners as $listener{
  137.             $listener->onWakeUp($record);
  138.         }
  139.     }
  140.     /**
  141.      * postClose
  142.      * an event invoked after Doctrine_Connection is closed
  143.      *
  144.      * @param Doctrine_Event $event 
  145.      * @return void 
  146.      */
  147.     public function postClose(Doctrine_Event $event)
  148.     {
  149.         foreach ($this->listeners as $listener{
  150.             $listener->postClose($event);
  151.         }
  152.     }
  153.     /**
  154.      * preClose
  155.      * an event invoked before Doctrine_Connection is closed
  156.      *
  157.      * @param Doctrine_Event $event 
  158.      * @return void 
  159.      */
  160.     public function preClose(Doctrine_Event $event)
  161.     {
  162.         foreach ($this->listeners as $listener{
  163.             $listener->preClose($event);
  164.         }
  165.     }
  166.     /**
  167.      * onOpen
  168.      * an event invoked after Doctrine_Connection is opened
  169.      *
  170.      * @param Doctrine_Connection $connection 
  171.      * @return void 
  172.      */
  173.     public function onOpen(Doctrine_Connection $connection)
  174.     {
  175.         foreach ($this->listeners as $listener{
  176.             $listener->onOpen($connection);
  177.         }
  178.     }
  179.     /**
  180.      * onTransactionCommit
  181.      * an event invoked after a Doctrine_Connection transaction is committed
  182.      *
  183.      * @param Doctrine_Event $event 
  184.      * @return void 
  185.      */
  186.     public function postTransactionCommit(Doctrine_Event $event)
  187.     {
  188.         foreach ($this->listeners as $listener{
  189.             $listener->postTransactionCommit($event);
  190.         }
  191.     }
  192.     /**
  193.      * onPreTransactionCommit
  194.      * an event invoked before a Doctrine_Connection transaction is committed
  195.      *
  196.      * @param Doctrine_Event $event 
  197.      * @return void 
  198.      */
  199.     public function preTransactionCommit(Doctrine_Event $event)
  200.     {
  201.         foreach ($this->listeners as $listener{
  202.             $listener->preTransactionCommit($event);
  203.         }
  204.     }
  205.     /**
  206.      * onTransactionRollback
  207.      * an event invoked after a Doctrine_Connection transaction is being rolled back
  208.      *
  209.      * @param Doctrine_Event $event 
  210.      * @return void 
  211.      */
  212.     public function postTransactionRollback(Doctrine_Event $event)
  213.     {
  214.         foreach ($this->listeners as $listener{
  215.             $listener->postTransactionRollback($event);
  216.         }
  217.     }
  218.     /**
  219.      * onPreTransactionRollback
  220.      * an event invoked before a Doctrine_Connection transaction is being rolled back
  221.      *
  222.      * @param Doctrine_Event $event 
  223.      * @return void 
  224.      */
  225.     public function preTransactionRollback(Doctrine_Event $event)
  226.     {
  227.         foreach ($this->listeners as $listener{
  228.             $listener->preTransactionRollback($event);
  229.         }
  230.     }
  231.     /**
  232.      * onTransactionBegin
  233.      * an event invoked after a Doctrine_Connection transaction has been started
  234.      *
  235.      * @param Doctrine_Event $event 
  236.      * @return void 
  237.      */
  238.     public function postTransactionBegin(Doctrine_Event $event)
  239.     {
  240.         foreach ($this->listeners as $listener{
  241.             $listener->postTransactionBegin($event);
  242.         }
  243.     }
  244.     /**
  245.      * onTransactionBegin
  246.      * an event invoked before a Doctrine_Connection transaction is being started
  247.      *
  248.      * @param Doctrine_Event $event 
  249.      * @return void 
  250.      */
  251.     public function preTransactionBegin(Doctrine_Event $event)
  252.     {
  253.         foreach ($this->listeners as $listener{
  254.             $listener->preTransactionBegin($event);
  255.         }
  256.     }
  257.     /**
  258.      * onCollectionDelete
  259.      * an event invoked after a Doctrine_Collection is being deleted
  260.      *
  261.      * @param Doctrine_Collection $collection 
  262.      * @return void 
  263.      */
  264.     public function onCollectionDelete(Doctrine_Collection $collection)
  265.     {
  266.         foreach ($this->listeners as $listener{
  267.             $listener->onCollectionDelete($collection);
  268.         }
  269.     }
  270.     /**
  271.      * onCollectionDelete
  272.      * an event invoked after a Doctrine_Collection is being deleted
  273.      *
  274.      * @param Doctrine_Collection $collection 
  275.      * @return void 
  276.      */
  277.     public function onPreCollectionDelete(Doctrine_Collection $collection)
  278.     {
  279.         foreach ($this->listeners as $listener{
  280.             $listener->onPreCollectionDelete($collection);
  281.         }
  282.     }
  283.     public function postConnect(Doctrine_Event $event)
  284.     {
  285.         foreach ($this->listeners as $listener{
  286.             $listener->postConnect($event);
  287.         }
  288.     }
  289.     public function preConnect(Doctrine_Event $event)
  290.     {
  291.         foreach ($this->listeners as $listener{
  292.             $listener->preConnect($event);
  293.         }
  294.     }
  295.     public function preQuery(Doctrine_Event $event)
  296.     
  297.         foreach ($this->listeners as $listener{
  298.             $listener->preQuery($event);
  299.         }
  300.     }
  301.     public function postQuery(Doctrine_Event $event)
  302.     {
  303.         foreach ($this->listeners as $listener{
  304.             $listener->postQuery($event);
  305.         }
  306.     }
  307.  
  308.     public function prePrepare(Doctrine_Event $event)
  309.     
  310.         foreach ($this->listeners as $listener{
  311.             $listener->prePrepare($event);
  312.         }
  313.     }
  314.     public function postPrepare(Doctrine_Event $event)
  315.     {
  316.         foreach ($this->listeners as $listener{
  317.             $listener->postPrepare($event);
  318.         }
  319.     }
  320.  
  321.     public function preExec(Doctrine_Event $event)
  322.     {
  323.         foreach ($this->listeners as $listener{
  324.             $listener->preExec($event);
  325.         }
  326.     }
  327.     public function postExec(Doctrine_Event $event)
  328.     {
  329.         foreach ($this->listeners as $listener{
  330.             $listener->postExec($event);
  331.         }
  332.     }
  333.  
  334.     public function preError(Doctrine_Event $event)
  335.     
  336.         foreach ($this->listeners as $listener{
  337.             $listener->preError($event);
  338.         }
  339.     }
  340.     public function postError(Doctrine_Event $event)
  341.     {
  342.         foreach ($this->listeners as $listener{
  343.             $listener->postError($event);
  344.         }
  345.     }
  346.  
  347.     public function preFetch(Doctrine_Event $event)
  348.     
  349.         foreach ($this->listeners as $listener{
  350.             $listener->preFetch($event);
  351.         }
  352.     }
  353.     public function postFetch(Doctrine_Event $event)
  354.     {
  355.         foreach ($this->listeners as $listener{
  356.             $listener->postFetch($event);
  357.         }
  358.     }
  359.  
  360.     public function preFetchAll(Doctrine_Event $event)
  361.     
  362.         foreach ($this->listeners as $listener{
  363.             $listener->preFetchAll($event);
  364.         }
  365.     }
  366.  
  367.     public function postFetchAll(Doctrine_Event $event)
  368.     {
  369.         foreach ($this->listeners as $listener{
  370.             $listener->postFetchAll($event);
  371.         }
  372.     }
  373.  
  374.     public function preStmtExecute(Doctrine_Event $event)
  375.     {
  376.         foreach ($this->listeners as $listener{
  377.             $listener->preStmtExecute($event);
  378.         }
  379.     }
  380.  
  381.     public function postStmtExecute(Doctrine_Event $event)
  382.     {
  383.         foreach ($this->listeners as $listener{
  384.             $listener->postStmtExecute($event);
  385.         }
  386.     }
  387. }