File indexing completed on 2024-05-12 06:02:42

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Json
0017  * @subpackage Expr
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * Class for Zend_Json encode method.
0025  *
0026  * This class simply holds a string with a native Javascript Expression,
0027  * so objects | arrays to be encoded with Zend_Json can contain native
0028  * Javascript Expressions.
0029  *
0030  * Example:
0031  * <code>
0032  * $foo = array(
0033  *     'integer'  =>9,
0034  *     'string'   =>'test string',
0035  *     'function' => Zend_Json_Expr(
0036  *         'function(){ window.alert("javascript function encoded by Zend_Json") }'
0037  *     ),
0038  * );
0039  *
0040  * Zend_Json::encode($foo, false, array('enableJsonExprFinder' => true));
0041  * // it will returns json encoded string:
0042  * // {"integer":9,"string":"test string","function":function(){window.alert("javascript function encoded by Zend_Json")}}
0043  * </code>
0044  *
0045  * @category   Zend
0046  * @package    Zend_Json
0047  * @subpackage Expr
0048  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0049  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0050  */
0051 class Zend_Json_Expr
0052 {
0053     /**
0054      * Storage for javascript expression.
0055      *
0056      * @var string
0057      */
0058     protected $_expression;
0059 
0060     /**
0061      * Constructor
0062      *
0063      * @param  string $expression the expression to hold.
0064      * @return void
0065      */
0066     public function __construct($expression)
0067     {
0068         $this->_expression = (string) $expression;
0069     }
0070 
0071     /**
0072      * Cast to string
0073      *
0074      * @return string holded javascript expression.
0075      */
0076     public function __toString()
0077     {
0078         return $this->_expression;
0079     }
0080 }