Hoa central
Where.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Database\Query;
38 
47 class Where
48 {
54  protected $_where = [];
55 
61  protected $_logicOperator = null;
62 
63 
64 
71  public function where($expression)
72  {
73  $where = null;
74 
75  if (!empty($this->_where)) {
76  $where = ($this->_logicOperator ?: 'AND') . ' ';
77  }
78 
79  if ($expression instanceof self) {
80  $expression = '(' . substr($expression, 7) . ')';
81  }
82 
83  $this->_where[] = $where . $expression;
84  $this->_logicOperator = null;
85 
86  return $this;
87  }
88 
96  public function __call($name, Array $values)
97  {
98  return call_user_func_array([$this, '_' . $name], $values);
99  }
100 
107  public function __get($name)
108  {
109  switch (strtolower($name)) {
110  case 'and':
111  case 'or':
112  $this->_logicOperator = strtoupper($name);
113 
114  break;
115 
116  default:
117  return $this->$name;
118  }
119 
120  return $this;
121  }
122 
128  public function reset()
129  {
130  $this->_where = [];
131 
132  return $this;
133  }
134 
140  public function __toString()
141  {
142  if (empty($this->_where)) {
143  return null;
144  }
145 
146  return ' WHERE ' . implode(' ', $this->_where);
147  }
148 }
__call($name, Array $values)
Definition: Where.php:96
where($expression)
Definition: Where.php:71