| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 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 |
|
|---|