Development

/branches/1.0/lib/view/escaper/sfOutputEscaperIteratorDecorator.class.php

You must first sign up to be able to contribute.

root/branches/1.0/lib/view/escaper/sfOutputEscaperIteratorDecorator.class.php

Revision 3232, 4.5 kB (checked in by fabien, 8 years ago)

updated phpdoc for lib/view directory (based on a patch from Rafael George)

  • 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  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * Output escaping iterator decorator.
13  *
14  * This takes an object that implements the Traversable interface and turns it
15  * into an iterator with each value escaped.
16  *
17  * Note: Prior to PHP 5.1, the IteratorIterator class was not implemented in the
18  * core of PHP. This means that although it will still work with classes that
19  * implement Iterator or IteratorAggregate, internal PHP classes that only
20  * implement the Traversable interface will cause the constructor to throw an
21  * exception.
22  *
23  * @see        sfOutputEscaper
24  * @package    symfony
25  * @subpackage view
26  * @author     Mike Squire <mike@somosis.co.uk>
27  * @version    SVN: $Id$
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     // Set the original value for __call(). Set our own iterator because passing
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
Note: See TracBrowser for help on using the browser.