CJavaScriptExpression.php 1.2 KB

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