Safe.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Symfony\Components\OutputEscaper;
  3. /*
  4. * This file is part of the symfony package.
  5. *
  6. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. /**
  12. * Marks a variable as being safe for output.
  13. *
  14. * @package symfony
  15. * @subpackage output_escaper
  16. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  17. */
  18. class Safe extends \ArrayIterator
  19. {
  20. protected
  21. $value = null;
  22. /**
  23. * Constructor.
  24. *
  25. * @param mixed $value The value to mark as safe
  26. */
  27. public function __construct($value)
  28. {
  29. $this->value = $value;
  30. if (is_array($value) || is_object($value))
  31. {
  32. parent::__construct($value);
  33. }
  34. }
  35. public function __toString()
  36. {
  37. return (string) $this->value;
  38. }
  39. public function __get($key)
  40. {
  41. return $this->value->$key;
  42. }
  43. public function __set($key, $value)
  44. {
  45. $this->value->$key = $value;
  46. }
  47. public function __call($method, $arguments)
  48. {
  49. return call_user_func_array(array($this->value, $method), $arguments);
  50. }
  51. public function __isset($key)
  52. {
  53. return isset($this->value->$key);
  54. }
  55. public function __unset($key)
  56. {
  57. unset($this->value->$key);
  58. }
  59. /**
  60. * Returns the embedded value.
  61. *
  62. * @return mixed The embedded value
  63. */
  64. public function getValue()
  65. {
  66. return $this->value;
  67. }
  68. }