PageRenderTime 39ms CodeModel.GetById 31ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/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/**
24 * Class for Zend_Json encode method.
25 *
26 * This class simply holds a string with a native Javascript Expression,
27 * so objects | arrays to be encoded with Zend_Json can contain native
28 * Javascript Expressions.
29 *
30 * Example:
31 * <code>
32 * $foo = array(
33 *     'integer'  =>9,
34 *     'string'   =>'test string',
35 *     'function' => Zend_Json_Expr(
36 *         'function(){ window.alert("javascript function encoded by Zend_Json") }'
37 *     ),
38 * );
39 *
40 * Zend_Json::encode($foo, false, array('enableJsonExprFinder' => true));
41 * // it will returns json encoded string:
42 * // {"integer":9,"string":"test string","function":function(){window.alert("javascript function encoded by Zend_Json")}}
43 * </code>
44 *
45 * @category   Zend
46 * @package    Zend_Json
47 * @subpackage Expr
48 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
49 * @license    http://framework.zend.com/license/new-bsd     New BSD License
50 */
51class Zend_Json_Expr
52{
53    /**
54     * Storage for javascript expression.
55     *
56     * @var string
57     */
58    protected $_expression;
59
60    /**
61     * Constructor
62     *
63     * @param  string $expression the expression to hold.
64     * @return void
65     */
66    public function __construct($expression)
67    {
68        $this->_expression = (string) $expression;
69    }
70
71    /**
72     * Cast to string
73     *
74     * @return string holded javascript expression.
75     */
76    public function __toString()
77    {
78        return $this->_expression;
79    }
80}