You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2KB

  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\web;
  8. use yii\base\Object;
  9. /**
  10. * JsExpression marks a string as a JavaScript expression.
  11. *
  12. * When using [[\yii\helpers\Json::encode()]] or [[\yii\helpers\Json::htmlEncode()]] to encode a value, JsonExpression objects
  13. * will be specially handled and encoded as a JavaScript expression instead of a string.
  14. *
  15. * @author Qiang Xue <qiang.xue@gmail.com>
  16. * @since 2.0
  17. */
  18. class JsExpression extends Object
  19. {
  20. /**
  21. * @var string the JavaScript expression represented by this object
  22. */
  23. public $expression;
  24. /**
  25. * Constructor.
  26. * @param string $expression the JavaScript expression represented by this object
  27. * @param array $config additional configurations for this object
  28. */
  29. public function __construct($expression, $config = [])
  30. {
  31. $this->expression = $expression;
  32. parent::__construct($config);
  33. }
  34. /**
  35. * The PHP magic function converting an object into a string.
  36. * @return string the JavaScript expression.
  37. */
  38. public function __toString()
  39. {
  40. return $this->expression;
  41. }
  42. }