Hoa central
Query.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Database\Query;
38 
39 use Hoa\Core;
40 
49 class Query
50 {
56  protected static $_queries = [];
57 
63  protected $_id = null;
64 
65 
66 
73  public function setId($id)
74  {
75  $this->_id = $id;
76 
77  return $this;
78  }
79 
85  public function getId()
86  {
87  return $this->_id;
88  }
89 
97  public function select($column = null)
98  {
99  return $this->store(new Select(func_get_args()));
100  }
101 
107  public function insert()
108  {
109  return $this->store(new Insert());
110  }
111 
117  public function update()
118  {
119  return $this->store(new Update());
120  }
121 
127  public function delete()
128  {
129  return $this->store(new Delete());
130  }
131 
138  public function where($expression)
139  {
140  $where = new Where();
141 
142  return $this->store($where->where($expression));
143  }
144 
151  protected function store($object)
152  {
153  if (null === $id = $this->getId()) {
154  $out = $object;
155  } else {
156  $out = static::$_queries[$id] = $object;
157  }
158 
159  $this->_id = null;
160 
161  return $out;
162  }
163 
170  public static function get($id)
171  {
172  if (null === $out = static::getReference($id)) {
173  return null;
174  }
175 
176  return clone $out;
177  }
178 
185  public static function getReference($id)
186  {
187  if (false === array_key_exists($id, static::$_queries)) {
188  return null;
189  }
190 
191  return static::$_queries[$id];
192  }
193 }
194 
198 Core\Consistency::flexEntity('Hoa\Database\Query\Query');
select($column=null)
Definition: Query.php:97
where($expression)
Definition: Query.php:138
static getReference($id)
Definition: Query.php:185