Development

/branches/1.2/lib/filter/sfFilterChain.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/filter/sfFilterChain.class.php

Revision 9087, 2.1 kB (checked in by Carl.Vondrick, 7 years ago)

1.1: fixed phpdoc to fit specs in filter (refs #2991)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6  * (c) 2004-2006 Sean Kerr <sean@code-box.org>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 /**
13  * sfFilterChain manages registered filters for a specific context.
14  *
15  * @package    symfony
16  * @subpackage filter
17  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
18  * @author     Sean Kerr <sean@code-box.org>
19  * @version    SVN: $Id$
20  */
21 class sfFilterChain
22 {
23   protected
24     $chain = array(),
25     $index = -1;
26
27   /**
28    * Loads filters configuration for a given action instance.
29    *
30    * @param sfComponent $actionInstance A sfComponent instance
31    */
32   public function loadConfiguration($actionInstance)
33   {
34     require(sfContext::getInstance()->getConfigCache()->checkConfig('modules/'.$actionInstance->getModuleName().'/config/filters.yml'));
35   }
36
37   /**
38    * Executes the next filter in this chain.
39    */
40   public function execute()
41   {
42     // skip to the next filter
43     ++$this->index;
44
45     if ($this->index < count($this->chain))
46     {
47       if (sfConfig::get('sf_logging_enabled'))
48       {
49         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Executing filter "%s"', get_class($this->chain[$this->index])))));
50       }
51
52       // execute the next filter
53       $this->chain[$this->index]->execute($this);
54     }
55   }
56
57   /**
58    * Returns true if the filter chain contains a filter of a given class.
59    *
60    * @param string $class The class name of the filter
61    *
62    * @return boolean true if the filter exists, false otherwise
63    */
64   public function hasFilter($class)
65   {
66     foreach ($this->chain as $filter)
67     {
68       if ($filter instanceof $class)
69       {
70         return true;
71       }
72     }
73
74     return false;
75   }
76
77   /**
78    * Registers a filter with this chain.
79    *
80    * @param sfFilter $filter A sfFilter implementation instance.
81    */
82   public function register($filter)
83   {
84     $this->chain[] = $filter;
85   }
86 }
87
Note: See TracBrowser for help on using the browser.