Просмотр исходного кода

[OutputEscaper] Moved __get() from Escaper to ObjectEscaper.

Kris Wallsmith 15 лет назад
Родитель
Сommit
ab26f9f3bf

+ 0 - 12
src/Symfony/Components/OutputEscaper/Escaper.php

@@ -233,18 +233,6 @@ abstract class Escaper
         return $this->value;
     }
 
-    /**
-     * Gets a value from the escaper.
-     *
-     * @param  string $var  Value to get
-     *
-     * @return mixed Value
-     */
-    public function __get($var)
-    {
-        return $this->escape($this->escaper, $this->value->$var);
-    }
-
     /**
      * Sets the current charset.
      *

+ 12 - 0
src/Symfony/Components/OutputEscaper/ObjectDecorator.php

@@ -94,4 +94,16 @@ class ObjectDecorator extends GetterDecorator
     {
         return $this->escape($this->escaper, (string) $this->value);
     }
+
+    /**
+     * Gets a value from the escaper.
+     *
+     * @param string $key The name of the value to get
+     *
+     * @return mixed The value from the wrapped object
+     */
+    public function __get($key)
+    {
+        return $this->escape($this->escaper, $this->value->$key);
+    }
 }

+ 7 - 0
tests/Symfony/Tests/Components/OutputEscaper/ObjectDecoratorTest.php

@@ -36,10 +36,17 @@ class ObjectDecoratorTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals('<strong>escaped!</strong>', self::$escaped->__toString(), 'The escaped object behaves like the real object');
     }
+
+    public function testMagicGet()
+    {
+        $this->assertEquals('<em>escape me</em>', self::$escaped->someMember, 'The escaped object behaves like the real object');
+    }
 }
 
 class OutputEscaperTest
 {
+    public $someMember = '<em>escape me</em>';
+
     public function __toString()
     {
         return $this->getTitle();