Development

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

You must first sign up to be able to contribute.

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

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