Skip to content

Commit 96304fa

Browse files
committed
Php 8 fixes
1 parent f1aee8e commit 96304fa

File tree

2 files changed

+80
-19
lines changed

2 files changed

+80
-19
lines changed

lib/view/escaper/sfOutputEscaperArrayDecorator.class.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
<?php
22

3-
/*
4-
* This file is part of the symfony package.
5-
* (c) 2004-2006 Fabien Potencier <[email protected]>
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-
203
/**
214
* Output escaping decorator class for arrays.
225
*

lib/view/escaper/sfOutputEscaperIteratorDecorator.class.php

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @author Mike Squire <[email protected]>
2727
* @version SVN: $Id: sfOutputEscaperIteratorDecorator.class.php 3232 2007-01-11 20:51:54Z fabien $
2828
*/
29-
class sfOutputEscaperIteratorDecorator extends sfOutputEscaperObjectDecorator implements Iterator, Countable, ArrayAccess
29+
class sfOutputEscaperIteratorDecorator extends sfOutputEscaperGetterDecorator implements Iterator, Countable, ArrayAccess
3030
{
3131
/**
3232
* The iterator to be used.
@@ -99,7 +99,7 @@ public function valid()
9999
{
100100
return $this->iterator->valid();
101101
}
102-
102+
103103
/**
104104
* Returns true if the supplied offset is set in the array (as required by
105105
* the ArrayAccess interface).
@@ -167,4 +167,82 @@ public function count()
167167
{
168168
return count($this->value);
169169
}
170+
171+
/**
172+
* Returns the result of calling the get() method on the object, bypassing
173+
* any escaping, if that method exists.
174+
*
175+
* If there is not a callable get() method this will throw an exception.
176+
*
177+
* @param string The parameter to be passed to the get() get method
178+
*
179+
* @return mixed The unescaped value returned
180+
*
181+
* @throws <b>sfException</b> if the object does not have a callable get() method
182+
*/
183+
public function getRaw($key)
184+
{
185+
if (!is_callable(array($this->value, 'get')))
186+
{
187+
throw new sfException('Object does not have a callable get() method.');
188+
}
189+
190+
return $this->value->get($key);
191+
}
192+
193+
/**
194+
* Magic PHP method that intercepts method calls, calls them on the objects
195+
* that is being escaped and escapes the result.
196+
*
197+
* The calling of the method is changed slightly to accommodate passing a
198+
* specific escaping strategy. An additional parameter is appended to the
199+
* argument list which is the escaping strategy. The decorator will remove
200+
* and use this parameter as the escaping strategy if it begins with 'esc_'
201+
* (the prefix all escaping helper functions have).
202+
*
203+
* For example if an object, $o, implements methods a() and b($arg):
204+
*
205+
* $o->a() // Escapes the return value of a()
206+
* $o->a(ESC_RAW) // Uses the escaping method ESC_RAW with a()
207+
* $o->b('a') // Escapes the return value of b('a')
208+
* $o->b('a', ESC_RAW); // Uses the escaping method ESC_RAW with b('a')
209+
*
210+
* @param string The method on the object to be called
211+
* @param array An array of arguments to be passed to the method
212+
*
213+
* @return mixed The escaped value returned by the method
214+
*/
215+
public function __call($method, $args)
216+
{
217+
if (count($args) > 0)
218+
{
219+
$escapingMethod = $args[count($args) - 1];
220+
if (is_string($escapingMethod) && substr($escapingMethod, 0, 4) === 'esc_')
221+
{
222+
array_pop($args);
223+
}
224+
else
225+
{
226+
$escapingMethod = $this->escapingMethod;
227+
}
228+
}
229+
else
230+
{
231+
$escapingMethod = $this->escapingMethod;
232+
}
233+
234+
$value = call_user_func_array(array($this->value, $method), $args);
235+
236+
return sfOutputEscaper::escape($escapingMethod, $value);
237+
}
238+
239+
/**
240+
* Try to call decorated object __toString() method if exists.
241+
*
242+
* @return string
243+
*/
244+
public function __toString()
245+
{
246+
return $this->escape($this->escapingMethod, $this->value->__toString());
247+
}
170248
}

0 commit comments

Comments
 (0)