From ab26f9f3bf1aa79a6fac14bda95c23258624435d Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Fri, 9 Jul 2010 06:07:51 -0700 Subject: [PATCH] [OutputEscaper] Moved __get() from Escaper to ObjectEscaper. --- src/Symfony/Components/OutputEscaper/Escaper.php | 12 ------------ .../Components/OutputEscaper/ObjectDecorator.php | 12 ++++++++++++ .../Components/OutputEscaper/ObjectDecoratorTest.php | 7 +++++++ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Components/OutputEscaper/Escaper.php b/src/Symfony/Components/OutputEscaper/Escaper.php index 42a7c879497d..28a93282bc69 100644 --- a/src/Symfony/Components/OutputEscaper/Escaper.php +++ b/src/Symfony/Components/OutputEscaper/Escaper.php @@ -233,18 +233,6 @@ public function getRawValue() 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. * diff --git a/src/Symfony/Components/OutputEscaper/ObjectDecorator.php b/src/Symfony/Components/OutputEscaper/ObjectDecorator.php index 30e0f6b5d51a..00ad535fb74e 100644 --- a/src/Symfony/Components/OutputEscaper/ObjectDecorator.php +++ b/src/Symfony/Components/OutputEscaper/ObjectDecorator.php @@ -94,4 +94,16 @@ public function __toString() { 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); + } } diff --git a/tests/Symfony/Tests/Components/OutputEscaper/ObjectDecoratorTest.php b/tests/Symfony/Tests/Components/OutputEscaper/ObjectDecoratorTest.php index 2e047661cfab..7af7a66ab548 100644 --- a/tests/Symfony/Tests/Components/OutputEscaper/ObjectDecoratorTest.php +++ b/tests/Symfony/Tests/Components/OutputEscaper/ObjectDecoratorTest.php @@ -36,10 +36,17 @@ public function testMagicToString() { $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 = 'escape me'; + public function __toString() { return $this->getTitle();