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

[OutputEscaper] Added magic __isset() method to object escaper.

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

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

@@ -106,4 +106,16 @@ class ObjectDecorator extends GetterDecorator
     {
         return $this->escape($this->escaper, $this->value->$key);
     }
+
+    /**
+     * Checks whether a value is set on the wrapped object.
+     *
+     * @param string $key The name of the value to check
+     *
+     * @return boolean Returns true if the value is set
+     */
+    public function __isset($key)
+    {
+        return isset($this->value->$key);
+    }
 }

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

@@ -41,6 +41,12 @@ class ObjectDecoratorTest extends \PHPUnit_Framework_TestCase
     {
         $this->assertEquals('<em>escape me</em>', self::$escaped->someMember, 'The escaped object behaves like the real object');
     }
+
+    public function testMagicIsset()
+    {
+        $this->assertTrue(isset(self::$escaped->someMember), 'The escaped object behaves like the real object');
+        $this->assertFalse(isset(self::$escaped->invalidMember), 'The escaped object behaves like the real object');
+    }
 }
 
 class OutputEscaperTest