Development

/branches/1.1/lib/filter/sfFilter.class.php

You must first sign up to be able to contribute.

root/branches/1.1/lib/filter/sfFilter.class.php

Revision 17858, 3.5 kB (checked in by FabianLange, 5 years ago)

[1.1, 1.2, 1.3] fixed some codeing standards (fixes #6376 - patch from gimler)

  • 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  * sfFilter provides a way for you to intercept incoming requests or outgoing responses.
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 abstract class sfFilter
22 {
23   protected
24     $parameterHolder = null,
25     $context         = null;
26
27   public static
28     $filterCalled    = array();
29
30   /**
31    * Class constructor.
32    *
33    * @see initialize()
34    */
35   public function __construct($context, $parameters = array())
36   {
37     $this->initialize($context, $parameters);
38   }
39
40   /**
41    * Initializes this Filter.
42    *
43    * @param sfContext $context    The current application context
44    * @param array     $parameters An associative array of initialization parameters
45    *
46    * @return boolean true, if initialization completes successfully, otherwise false
47    *
48    * @throws <b>sfInitializationException</b> If an error occurs while initializing this Filter
49    */
50   public function initialize($context, $parameters = array())
51   {
52     $this->context = $context;
53
54     $this->parameterHolder = new sfParameterHolder();
55     $this->parameterHolder->add($parameters);
56
57     return true;
58   }
59
60   /**
61    * Returns true if this is the first call to the sfFilter instance.
62    *
63    * @return boolean true if this is the first call to the sfFilter instance, false otherwise
64    */
65   protected function isFirstCall()
66   {
67     $class = get_class($this);
68     if (isset(self::$filterCalled[$class]))
69     {
70       return false;
71     }
72     else
73     {
74       self::$filterCalled[$class] = true;
75
76       return true;
77     }
78   }
79
80   /**
81    * Retrieves the current application context.
82    *
83    * @return sfContext The current sfContext instance
84    */
85   public final function getContext()
86   {
87     return $this->context;
88   }
89
90   /**
91    * Gets the parameter holder for this object.
92    *
93    * @return sfParameterHolder A sfParameterHolder instance
94    */
95   public function getParameterHolder()
96   {
97     return $this->parameterHolder;
98   }
99
100   /**
101    * Gets the parameter associated with the given key.
102    *
103    * This is a shortcut for:
104    *
105    * <code>$this->getParameterHolder()->get()</code>
106    *
107    * @param string $name    The key name
108    * @param string $default The default value
109    *
110    * @return string The value associated with the key
111    *
112    * @see sfParameterHolder
113    */
114   public function getParameter($name, $default = null)
115   {
116     return $this->parameterHolder->get($name, $default);
117   }
118
119   /**
120    * Returns true if the given key exists in the parameter holder.
121    *
122    * This is a shortcut for:
123    *
124    * <code>$this->getParameterHolder()->has()</code>
125    *
126    * @param string $name The key name
127    *
128    * @return boolean true if the given key exists, false otherwise
129    *
130    * @see sfParameterHolder
131    */
132   public function hasParameter($name)
133   {
134     return $this->parameterHolder->has($name);
135   }
136
137   /**
138    * Sets the value for the given key.
139    *
140    * This is a shortcut for:
141    *
142    * <code>$this->getParameterHolder()->set()</code>
143    *
144    * @param string $name  The key name
145    * @param string $value The value
146    *
147    * @see sfParameterHolder
148    */
149   public function setParameter($name, $value)
150   {
151     return $this->parameterHolder->set($name, $value);
152   }
153 }
154
Note: See TracBrowser for help on using the browser.