Development

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

You must first sign up to be able to contribute.

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

Revision 23810, 3.4 kB (checked in by Kris.Wallsmith, 4 years ago)

[1.3] set svn:eol-style property to native and svn:keywords property to Id on all .php files

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
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
47    */
48   public function initialize($context, $parameters = array())
49   {
50     $this->context = $context;
51
52     $this->parameterHolder = new sfParameterHolder();
53     $this->parameterHolder->add($parameters);
54
55     return true;
56   }
57
58   /**
59    * Returns true if this is the first call to the sfFilter instance.
60    *
61    * @return boolean true if this is the first call to the sfFilter instance, false otherwise
62    */
63   protected function isFirstCall()
64   {
65     $class = get_class($this);
66     if (isset(self::$filterCalled[$class]))
67     {
68       return false;
69     }
70     else
71     {
72       self::$filterCalled[$class] = true;
73
74       return true;
75     }
76   }
77
78   /**
79    * Retrieves the current application context.
80    *
81    * @return sfContext The current sfContext instance
82    */
83   public final function getContext()
84   {
85     return $this->context;
86   }
87
88   /**
89    * Gets the parameter holder for this object.
90    *
91    * @return sfParameterHolder A sfParameterHolder instance
92    */
93   public function getParameterHolder()
94   {
95     return $this->parameterHolder;
96   }
97
98   /**
99    * Gets the parameter associated with the given key.
100    *
101    * This is a shortcut for:
102    *
103    * <code>$this->getParameterHolder()->get()</code>
104    *
105    * @param string $name    The key name
106    * @param string $default The default value
107    *
108    * @return string The value associated with the key
109    *
110    * @see sfParameterHolder
111    */
112   public function getParameter($name, $default = null)
113   {
114     return $this->parameterHolder->get($name, $default);
115   }
116
117   /**
118    * Returns true if the given key exists in the parameter holder.
119    *
120    * This is a shortcut for:
121    *
122    * <code>$this->getParameterHolder()->has()</code>
123    *
124    * @param string $name The key name
125    *
126    * @return boolean true if the given key exists, false otherwise
127    *
128    * @see sfParameterHolder
129    */
130   public function hasParameter($name)
131   {
132     return $this->parameterHolder->has($name);
133   }
134
135   /**
136    * Sets the value for the given key.
137    *
138    * This is a shortcut for:
139    *
140    * <code>$this->getParameterHolder()->set()</code>
141    *
142    * @param string $name  The key name
143    * @param string $value The value
144    *
145    * @see sfParameterHolder
146    */
147   public function setParameter($name, $value)
148   {
149     return $this->parameterHolder->set($name, $value);
150   }
151 }
152
Note: See TracBrowser for help on using the browser.