소스 검색

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

Kris Wallsmith 15 년 전
부모
커밋
fe7e01c653
2개의 변경된 파일18개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      src/Symfony/Components/OutputEscaper/ObjectDecorator.php
  2. 6 0
      tests/Symfony/Tests/Components/OutputEscaper/ObjectDecoratorTest.php

+ 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