Development

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

You must first sign up to be able to contribute.

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

Revision 3232, 4.2 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 // fix for PHP 5.0 (no Countable interface)
12 if (!interface_exists('Countable', false))
13 {
14   interface Countable
15   {
16     public function count();
17   }
18 }
19
20 /**
21  * Output escaping decorator class for arrays.
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 sfOutputEscaperArrayDecorator extends sfOutputEscaperGetterDecorator implements Iterator, ArrayAccess, Countable
30 {
31   /**
32    * Used by the iterator to know if the current element is valid.
33    *
34    * @var int
35    */
36   private $count;
37
38   /**
39    * Reset the array to the beginning (as required for the Iterator interface).
40    */
41   public function rewind()
42   {
43     reset($this->value);
44
45     $this->count = count($this->value);
46   }
47
48   /**
49    * Get the key associated with the current value (as required by the Iterator interface).
50    *
51    * @return string The key
52    */
53   public function key()
54   {
55     return key($this->value);
56   }
57
58   /**
59    * Escapes and return the current value (as required by the Iterator interface).
60    *
61    * This escapes the value using {@link sfOutputEscaper::escape()} with
62    * whatever escaping method is set for this instance.
63    *
64    * @return mixed The escaped value
65    */
66   public function current()
67   {
68     return sfOutputEscaper::escape($this->escapingMethod, current($this->value));
69   }
70
71   /**
72    * Moves to the next element (as required by the Iterator interface).
73    */
74   public function next()
75   {
76     next($this->value);
77
78     $this->count --;
79   }
80
81   /**
82    * Returns true if the current element is valid (as required by the Iterator interface).
83    *
84    * The current element will not be valid if {@link next()} has fallen off the
85    * end of the array or if there are no elements in the array and {@link
86    * rewind()} was called.
87    *
88    * @return boolean The validity of the current element; true if it is valid
89    */
90   public function valid()
91   {
92     return $this->count > 0;
93   }
94
95   /**
96    * Returns true if the supplied offset is set in the array (as required by the ArrayAccess interface).
97    *
98    * @param string The offset of the value to check existance of
99    *
100    * @return boolean true if the offset exists; false otherwise
101    */
102   public function offsetExists($offset)
103   {
104     return array_key_exists($offset, $this->value);
105   }
106
107   /**
108    * Returns the element associated with the offset supplied (as required by the ArrayAccess interface).
109    *
110    * @param string The offset of the value to get
111    *
112    * @return mixed The escaped value
113    */
114   public function offsetGet($offset)
115   {
116     return sfOutputEscaper::escape($this->escapingMethod, $this->value[$offset]);
117   }
118
119   /**
120    * Throws an exception saying that values cannot be set (this method is
121    * required for the ArrayAccess interface).
122    *
123    * This (and the other sfOutputEscaper classes) are designed to be read only
124    * so this is an illegal operation.
125    *
126    * @param string (ignored)
127    * @param string (ignored)
128    *
129    * @throws <b>sfException</b>
130    */
131   public function offsetSet($offset, $value)
132   {
133     throw new sfException('Cannot set values.');
134   }
135
136   /**
137    * Throws an exception saying that values cannot be unset (this method is
138    * required for the ArrayAccess interface).
139    *
140    * This (and the other sfOutputEscaper classes) are designed to be read only
141    * so this is an illegal operation.
142    *
143    * @param string (ignored)
144    *
145    * @throws sfException
146    */
147   public function offsetUnset($offset)
148   {
149     throw new sfException('Cannot unset values.');
150   }
151
152   /**
153    * Returns the size of the array (are required by the Countable interface).
154    *
155    * @return int The size of the array
156    */
157   public function count()
158   {
159     return count($this->value);
160   }
161
162   /**
163    * Returns the (unescaped) value from the array associated with the key supplied.
164    *
165    * @param string The key into the array to use
166    *
167    * @return mixed The value
168    */
169   public function getRaw($key)
170   {
171     return $this->value[$key];
172   }
173 }
174
Note: See TracBrowser for help on using the browser.