Browse Source

[OutputEscaper] added SafeDecoratorInterface

Fabien Potencier 14 years ago
parent
commit
6aa190b2a6

+ 6 - 6
src/Symfony/Component/OutputEscaper/Escaper.php

@@ -118,18 +118,18 @@ abstract class Escaper
                 return $copy;
             }
 
-            if (self::isClassMarkedAsSafe(get_class($value))) {
-                // the class or one of its children is marked as safe
-                // return the unescaped object
-                return $value;
-            }
-
             if ($value instanceof SafeDecorator) {
                 // do not escape objects marked as safe
                 // return the original object
                 return $value->getValue();
             }
 
+            if (self::isClassMarkedAsSafe(get_class($value)) || $value instanceof SafeDecoratorInterface) {
+                // the class or one of its children is marked as safe
+                // return the unescaped object
+                return $value;
+            }
+
             if ($value instanceof \Traversable) {
                 return new IteratorDecorator($escaper, $value);
             }

+ 1 - 1
src/Symfony/Component/OutputEscaper/SafeDecorator.php

@@ -16,7 +16,7 @@ namespace Symfony\Component\OutputEscaper;
  *
  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  */
-class SafeDecorator extends \ArrayIterator
+class SafeDecorator extends \ArrayIterator implements SafeDecoratorInterface
 {
     protected $value;
 

+ 21 - 0
src/Symfony/Component/OutputEscaper/SafeDecoratorInterface.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace Symfony\Component\OutputEscaper;
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Marks a class as being safe for output.
+ *
+ * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
+ */
+interface SafeDecoratorInterface
+{
+}