Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

62 lines
1.6KB

  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\db;
  8. /**
  9. * Expression represents a DB expression that does not need escaping or quoting.
  10. * When an Expression object is embedded within a SQL statement or fragment,
  11. * it will be replaced with the [[expression]] property value without any
  12. * DB escaping or quoting. For example,
  13. *
  14. * ~~~
  15. * $expression = new Expression('NOW()');
  16. * $sql = 'SELECT ' . $expression; // SELECT NOW()
  17. * ~~~
  18. *
  19. * An expression can also be bound with parameters specified via [[params]].
  20. *
  21. * @author Qiang Xue <qiang.xue@gmail.com>
  22. * @since 2.0
  23. */
  24. class Expression extends \yii\base\Object
  25. {
  26. /**
  27. * @var string the DB expression
  28. */
  29. public $expression;
  30. /**
  31. * @var array list of parameters that should be bound for this expression.
  32. * The keys are placeholders appearing in [[expression]] and the values
  33. * are the corresponding parameter values.
  34. */
  35. public $params = [];
  36. /**
  37. * Constructor.
  38. * @param string $expression the DB expression
  39. * @param array $params parameters
  40. * @param array $config name-value pairs that will be used to initialize the object properties
  41. */
  42. public function __construct($expression, $params = [], $config = [])
  43. {
  44. $this->expression = $expression;
  45. $this->params = $params;
  46. parent::__construct($config);
  47. }
  48. /**
  49. * String magic method
  50. * @return string the DB expression
  51. */
  52. public function __toString()
  53. {
  54. return $this->expression;
  55. }
  56. }