/framework/vendor/zend/Zend/Json/Expr.php

http://zoop.googlecode.com/ · PHP · 80 lines · 13 code · 3 blank · 64 comment · 0 complexity · 7a40039b5e3100725a598ae4bf7c60cd MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Json
  17. * @subpackage Expr
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Expr.php 20096 2010-01-06 02:05:09Z bkarwin $
  21. */
  22. /**
  23. * Class for Zend_Json encode method.
  24. *
  25. * This class simply holds a string with a native Javascript Expression,
  26. * so objects | arrays to be encoded with Zend_Json can contain native
  27. * Javascript Expressions.
  28. *
  29. * Example:
  30. * <code>
  31. * $foo = array(
  32. * 'integer' =>9,
  33. * 'string' =>'test string',
  34. * 'function' => Zend_Json_Expr(
  35. * 'function(){ window.alert("javascript function encoded by Zend_Json") }'
  36. * ),
  37. * );
  38. *
  39. * Zend_Json::encode($foo, false, array('enableJsonExprFinder' => true));
  40. * // it will returns json encoded string:
  41. * // {"integer":9,"string":"test string","function":function(){window.alert("javascript function encoded by Zend_Json")}}
  42. * </code>
  43. *
  44. * @category Zend
  45. * @package Zend_Json
  46. * @subpackage Expr
  47. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  48. * @license http://framework.zend.com/license/new-bsd New BSD License
  49. */
  50. class Zend_Json_Expr
  51. {
  52. /**
  53. * Storage for javascript expression.
  54. *
  55. * @var string
  56. */
  57. protected $_expression;
  58. /**
  59. * Constructor
  60. *
  61. * @param string $expression the expression to hold.
  62. * @return void
  63. */
  64. public function __construct($expression)
  65. {
  66. $this->_expression = (string) $expression;
  67. }
  68. /**
  69. * Cast to string
  70. *
  71. * @return string holded javascript expression.
  72. */
  73. public function __toString()
  74. {
  75. return $this->_expression;
  76. }
  77. }