1: <?php
 2: /**
 3:  * CJavaScriptExpression class file.
 4:  *
 5:  * @author Alexander Makarov <sam@rmcreative.ru>
 6:  * @link http://www.yiiframework.com/
 7:  * @copyright Copyright © 2012 Yii Software LLC
 8:  * @license http://www.yiiframework.com/license/
 9:  */
10: 
11: /**
12:  * CJavaScriptExpression represents a JavaScript expression that does not need escaping.
13:  * It can be passed to {@link CJavaScript::encode()} and the code will stay as is.
14:  *
15:  * @author Alexander Makarov <sam@rmcreative.ru>
16:  * @package system.web.helpers
17:  * @since 1.1.11
18:  */
19: class CJavaScriptExpression
20: {
21:     /**
22:      * @var string the javascript expression wrapped by this object
23:      */
24:     public $code;
25: 
26:     /**
27:      * @param string $code a javascript expression that is to be wrapped by this object
28:      * @throws CException if argument is not a string
29:      */
30:     public function __construct($code)
31:     {
32:         if(!is_string($code))
33:             throw new CException('Value passed to CJavaScriptExpression should be a string.');
34:         if(strpos($code, 'js:')===0)
35:             $code=substr($code,3);
36:         $this->code=$code;
37:     }
38: 
39:     /**
40:      * String magic method
41:      * @return string the javascript expression wrapped by this object
42:      */
43:     public function __toString()
44:     {
45:         return $this->code;
46:     }
47: }