| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
class sfOutputEscaperIteratorDecorator extends sfOutputEscaperObjectDecorator implements Iterator, Countable, ArrayAccess |
|---|
| 30 |
{ |
|---|
| 31 |
|
|---|
| 32 |
* The iterator to be used. |
|---|
| 33 |
* |
|---|
| 34 |
* @var IteratorIterator |
|---|
| 35 |
*/ |
|---|
| 36 |
private $iterator; |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
* Constructs a new escaping iteratoror using the escaping method and value supplied. |
|---|
| 40 |
* |
|---|
| 41 |
* @param string The escaping method to use |
|---|
| 42 |
* @param Traversable The iterator to escape |
|---|
| 43 |
*/ |
|---|
| 44 |
public function __construct($escapingMethod, Traversable $value) |
|---|
| 45 |
{ |
|---|
| 46 |
|
|---|
| 47 |
// it to IteratorIterator will lose any other method calls. |
|---|
| 48 |
|
|---|
| 49 |
parent::__construct($escapingMethod, $value); |
|---|
| 50 |
|
|---|
| 51 |
$this->iterator = new IteratorIterator($value); |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
* Resets the iterator (as required by the Iterator interface). |
|---|
| 56 |
* |
|---|
| 57 |
* @return boolean true, if the iterator rewinds successfully otherwise false |
|---|
| 58 |
*/ |
|---|
| 59 |
public function rewind() |
|---|
| 60 |
{ |
|---|
| 61 |
return $this->iterator->rewind(); |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
* Escapes and gets the current element (as required by the Iterator interface). |
|---|
| 66 |
* |
|---|
| 67 |
* @return mixed The escaped value |
|---|
| 68 |
*/ |
|---|
| 69 |
public function current() |
|---|
| 70 |
{ |
|---|
| 71 |
return sfOutputEscaper::escape($this->escapingMethod, $this->iterator->current()); |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
* Gets the current key (as required by the Iterator interface). |
|---|
| 76 |
* |
|---|
| 77 |
* @return string Iterator key |
|---|
| 78 |
*/ |
|---|
| 79 |
public function key() |
|---|
| 80 |
{ |
|---|
| 81 |
return $this->iterator->key(); |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
* Moves to the next element in the iterator (as required by the Iterator interface). |
|---|
| 86 |
*/ |
|---|
| 87 |
public function next() |
|---|
| 88 |
{ |
|---|
| 89 |
return $this->iterator->next(); |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
* Returns whether the current element is valid or not (as required by the |
|---|
| 94 |
* Iterator interface). |
|---|
| 95 |
* |
|---|
| 96 |
* @return boolean true if the current element is valid; false otherwise |
|---|
| 97 |
*/ |
|---|
| 98 |
public function valid() |
|---|
| 99 |
{ |
|---|
| 100 |
return $this->iterator->valid(); |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
* Returns true if the supplied offset is set in the array (as required by |
|---|
| 105 |
* the ArrayAccess interface). |
|---|
| 106 |
* |
|---|
| 107 |
* @param string The offset of the value to check existance of |
|---|
| 108 |
* |
|---|
| 109 |
* @return boolean true if the offset exists; false otherwise |
|---|
| 110 |
*/ |
|---|
| 111 |
public function offsetExists($offset) |
|---|
| 112 |
{ |
|---|
| 113 |
return array_key_exists($offset, $this->value); |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
* Returns the element associated with the offset supplied (as required by the ArrayAccess interface). |
|---|
| 118 |
* |
|---|
| 119 |
* @param string The offset of the value to get |
|---|
| 120 |
* |
|---|
| 121 |
* @return mixed The escaped value |
|---|
| 122 |
*/ |
|---|
| 123 |
public function offsetGet($offset) |
|---|
| 124 |
{ |
|---|
| 125 |
return sfOutputEscaper::escape($this->escapingMethod, $this->value[$offset]); |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
* Throws an exception saying that values cannot be set (this method is |
|---|
| 130 |
* required for the ArrayAccess interface). |
|---|
| 131 |
* |
|---|
| 132 |
* This (and the other sfOutputEscaper classes) are designed to be read only |
|---|
| 133 |
* so this is an illegal operation. |
|---|
| 134 |
* |
|---|
| 135 |
* @param string (ignored) |
|---|
| 136 |
* @param string (ignored) |
|---|
| 137 |
* |
|---|
| 138 |
* @throws <b>sfException</b> |
|---|
| 139 |
*/ |
|---|
| 140 |
public function offsetSet($offset, $value) |
|---|
| 141 |
{ |
|---|
| 142 |
throw new sfException('Cannot set values.'); |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
* Throws an exception saying that values cannot be unset (this method is |
|---|
| 147 |
* required for the ArrayAccess interface). |
|---|
| 148 |
* |
|---|
| 149 |
* This (and the other sfOutputEscaper classes) are designed to be read only |
|---|
| 150 |
* so this is an illegal operation. |
|---|
| 151 |
* |
|---|
| 152 |
* @param string (ignored) |
|---|
| 153 |
* |
|---|
| 154 |
* @throws <b>sfException</b> |
|---|
| 155 |
*/ |
|---|
| 156 |
public function offsetUnset($offset) |
|---|
| 157 |
{ |
|---|
| 158 |
throw new sfException('Cannot unset values.'); |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
* Returns the size of the array (are required by the Countable interface). |
|---|
| 163 |
* |
|---|
| 164 |
* @return int The size of the array |
|---|
| 165 |
*/ |
|---|
| 166 |
public function count() |
|---|
| 167 |
{ |
|---|
| 168 |
return count($this->value); |
|---|
| 169 |
} |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|