mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-11-01 03:26:36 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| /**
 | |
|  * @link https://www.yiiframework.com/
 | |
|  * @copyright Copyright (c) 2008 Yii Software LLC
 | |
|  * @license https://www.yiiframework.com/license/
 | |
|  */
 | |
| 
 | |
| namespace yii\web;
 | |
| 
 | |
| use yii\base\BaseObject;
 | |
| 
 | |
| /**
 | |
|  * `JsExpression` marks a string as a JavaScript expression.
 | |
|  *
 | |
|  * When using [[\yii\helpers\Json::encode()]] or [[\yii\helpers\Json::htmlEncode()]] to encode a value, `JsExpression` objects
 | |
|  * will be specially handled and encoded as a JavaScript expression instead of a string.
 | |
|  *
 | |
|  * @author Qiang Xue <qiang.xue@gmail.com>
 | |
|  * @since 2.0
 | |
|  */
 | |
| class JsExpression extends BaseObject
 | |
| {
 | |
|     /**
 | |
|      * @var string the JavaScript expression represented by this object
 | |
|      */
 | |
|     public $expression;
 | |
| 
 | |
| 
 | |
|     /**
 | |
|      * Constructor.
 | |
|      * @param string $expression the JavaScript expression represented by this object
 | |
|      * @param array $config additional configurations for this object
 | |
|      */
 | |
|     public function __construct($expression, $config = [])
 | |
|     {
 | |
|         $this->expression = $expression;
 | |
|         parent::__construct($config);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * The PHP magic function converting an object into a string.
 | |
|      * @return string the JavaScript expression.
 | |
|      */
 | |
|     public function __toString()
 | |
|     {
 | |
|         return (string) $this->expression;
 | |
|     }
 | |
| }
 | 
