Development

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

You must first sign up to be able to contribute.

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

Revision 9158, 4.1 kB (checked in by FabianLange, 6 years ago)

fixed sfOutputEscaper* to return isset($var[index]) correctly. Fixes #3415

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