Browse Source

[OutputEscaper] made getEscaper*() methods more consistent with the way you can change the escaping strategy in __call()

Fabien Potencier 14 years ago
parent
commit
e23c3cc702

+ 2 - 2
src/Symfony/Component/OutputEscaper/ArrayDecorator.php

@@ -145,11 +145,11 @@ class ArrayDecorator extends BaseEscaper implements \Iterator, \ArrayAccess, \Co
      * Escapes a key from the array using the specified escaper.
      *
      * @param string $key     The array key
-     * @param mixed  $escaper The escaping method (a PHP callable or a named escaper)
+     * @param string $escaper The escaping strategy prefixed with esc_ (see __call())
      */
     public function getEscapedKey($key, $escaper)
     {
-        return Escaper::escape($escaper, $this->value[$key]);
+        return Escaper::escape(substr($escaper, 4), $this->value[$key]);
     }
 
     /**

+ 4 - 4
src/Symfony/Component/OutputEscaper/ObjectDecorator.php

@@ -100,11 +100,11 @@ class ObjectDecorator extends BaseEscaper implements \ArrayAccess, \Countable
      * Escapes an object property using the specified escaper.
      *
      * @param string $key     The object property name
-     * @param mixed  $escaper The escaping method (a PHP callable or a named escaper)
+     * @param string $escaper The escaping strategy prefixed with esc_ (see __call())
      */
     public function getEscapedProperty($key, $escaper)
     {
-        return Escaper::escape($escaper, $this->value->$key);
+        return Escaper::escape(substr($escaper, 4), $this->value->$key);
     }
 
     /**
@@ -168,11 +168,11 @@ class ObjectDecorator extends BaseEscaper implements \ArrayAccess, \Countable
      * Escapes a key from the array using the specified escaper.
      *
      * @param string $key     The array key
-     * @param mixed  $escaper The escaping method (a PHP callable or a named escaper)
+     * @param string $escaper The escaping strategy prefixed with esc_ (see __call())
      */
     public function getEscapedKey($key, $escaper)
     {
-        return Escaper::escape($escaper, $this->value[$key]);
+        return Escaper::escape(substr($escaper, 4), $this->value[$key]);
     }
 
     /**

+ 1 - 1
tests/Symfony/Tests/Component/OutputEscaper/ArrayDecoratorTest.php

@@ -26,7 +26,7 @@ class ArrayDecoratorTest extends \PHPUnit_Framework_TestCase
 
     public function testGetEscapedKey()
     {
-        $this->assertEquals('<strong>escaped!</strong>', self::$escaped->getEscapedKey(0, 'raw'), '->getEscapedKey() returns the value with an other escaper');
+        $this->assertEquals('<strong>escaped!</strong>', self::$escaped->getEscapedKey(0, 'esc_raw'), '->getEscapedKey() returns the value with an other escaper');
     }
 
     public function testArrayAccessInterface()