Development

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

You must first sign up to be able to contribute.

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

Revision 7791, 1.7 kB (checked in by fabien, 6 years ago)

updated Sean Kerr email address

  • 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    * Executes the next filter in this chain.
29    */
30   public function execute()
31   {
32     // skip to the next filter
33     ++$this->index;
34
35     if ($this->index < count($this->chain))
36     {
37       if (sfConfig::get('sf_logging_enabled'))
38       {
39         sfContext::getInstance()->getLogger()->info(sprintf('{sfFilter} executing filter "%s"', get_class($this->chain[$this->index])));
40       }
41
42       // execute the next filter
43       $this->chain[$this->index]->execute($this);
44     }
45   }
46
47   /**
48    * Returns true if the filter chain contains a filter of a given class.
49    *
50    * @param string The class name of the filter
51    *
52    * @return boolean true if the filter exists, false otherwise
53    */
54   public function hasFilter($class)
55   {
56     foreach ($this->chain as $filter)
57     {
58       if ($filter instanceof $class)
59       {
60         return true;
61       }
62     }
63
64     return false;
65   }
66
67   /**
68    * Registers a filter with this chain.
69    *
70    * @param sfFilter A sfFilter implementation instance.
71    */
72   public function register($filter)
73   {
74     $this->chain[] = $filter;
75   }
76 }
77
Note: See TracBrowser for help on using the browser.