1 | <?php |
||
16 | class ModelManager |
||
17 | { |
||
18 | /** |
||
19 | * The base query builder instance. |
||
20 | * |
||
21 | * @var \Childish\query\Builder |
||
22 | */ |
||
23 | protected $query; |
||
24 | |||
25 | /** |
||
26 | * The model being queried. |
||
27 | * |
||
28 | * @var \Childish\ChildishModel |
||
29 | */ |
||
30 | protected $model; |
||
31 | |||
32 | /** |
||
33 | * The query union statements. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | public $unions; |
||
38 | /** |
||
39 | * The methods that should be returned from query builder. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $passthru = [ |
||
44 | 'insert', 'insertGetId', 'getBindings', 'toSql', |
||
45 | 'exists', 'count', 'min', 'max', 'avg', 'sum', 'getConnection', |
||
46 | ]; |
||
47 | |||
48 | |||
49 | /** |
||
50 | * Create a new Eloquent query builder instance. |
||
51 | * |
||
52 | * @param \Childish\query\Builder $query |
||
53 | * @return mixed|void |
||
|
|||
54 | */ |
||
55 | public function __construct(Builder $query) |
||
59 | |||
60 | /** |
||
61 | * Set a model instance for the model being queried. |
||
62 | * |
||
63 | * @param \Childish\ChildishModel $model |
||
64 | * @return $this |
||
65 | */ |
||
66 | public function setModel(ChildishModel $model) |
||
74 | |||
75 | /** |
||
76 | * Get the model instance being queried. |
||
77 | * |
||
78 | * @return \Childish\ChildishModel |
||
79 | */ |
||
80 | public function getModel() |
||
84 | |||
85 | /** |
||
86 | * update |
||
87 | * |
||
88 | * @param $values |
||
89 | * @return int |
||
90 | */ |
||
91 | public function update($values) |
||
95 | |||
96 | /** |
||
97 | * insert |
||
98 | * |
||
99 | * @param $values |
||
100 | * @return int |
||
101 | */ |
||
102 | public function insert($values) |
||
106 | |||
107 | /** |
||
108 | * insertGetId |
||
109 | * |
||
110 | * @param $values |
||
111 | * @return int |
||
112 | */ |
||
113 | public function insertGetId($values) |
||
117 | |||
118 | /** |
||
119 | * updateOrInsert |
||
120 | * |
||
121 | * @param $values |
||
122 | * @return bool |
||
123 | */ |
||
124 | public function updateOrInsert($values) |
||
128 | |||
129 | /** |
||
130 | * Get a single column's value from the first result of a query. |
||
131 | * |
||
132 | * @param string $column |
||
133 | * @return mixed |
||
134 | */ |
||
135 | public function value($column) |
||
141 | |||
142 | /** |
||
143 | * Execute the query as a "select" statement. |
||
144 | * |
||
145 | * @param array $columns |
||
146 | * @return \Childish\support\Collection|static[]\ |
||
147 | */ |
||
148 | public function get($columns = ['*']) |
||
152 | |||
153 | /** |
||
154 | * Get the hydrated models without eager loading. |
||
155 | * |
||
156 | * @param array $columns |
||
157 | * @return \Childish\ChildishModel[] |
||
158 | */ |
||
159 | public function getModels($columns = ['*']) |
||
165 | |||
166 | /** |
||
167 | * Create a collection of models from plain arrays. |
||
168 | * |
||
169 | * @param array $items |
||
170 | * @return \Childish\support\Collection |
||
171 | */ |
||
172 | public function hydrate(array $items) |
||
180 | |||
181 | /** |
||
182 | * Create a new instance of the model being queried. |
||
183 | * |
||
184 | * @param array $attributes |
||
185 | * @return \Childish\ChildishModel |
||
186 | */ |
||
187 | public function newModelInstance($attributes = []) |
||
193 | |||
194 | |||
195 | /** |
||
196 | * Execute the query and get the first result. |
||
197 | * |
||
198 | * @param array $columns |
||
199 | * @return \Childish\ChildishModel|static|null |
||
200 | */ |
||
201 | public function first($columns = ['*']) |
||
205 | |||
206 | /** |
||
207 | * Alias to set the "limit" value of the query. |
||
208 | * |
||
209 | * @param int $value |
||
210 | * @return \Childish\query\Builder|static |
||
211 | */ |
||
212 | public function take($value) |
||
216 | |||
217 | /** |
||
218 | * Set the "limit" value of the query. |
||
219 | * |
||
220 | * @param int $value |
||
221 | * @return $this |
||
222 | */ |
||
223 | public function limit($value) |
||
233 | |||
234 | |||
235 | /** |
||
236 | * Get the underlying query builder instance. |
||
237 | * |
||
238 | * @return \Childish\query\Builder |
||
239 | */ |
||
240 | public function getQuery() |
||
244 | |||
245 | /** |
||
246 | * Set the underlying query builder instance. |
||
247 | * |
||
248 | * @param \Childish\query\Builder $query |
||
249 | * @return $this |
||
250 | */ |
||
251 | public function setQuery($query) |
||
257 | |||
258 | |||
259 | /** |
||
260 | * Add the "updated at" column to an array of values. |
||
261 | * |
||
262 | * @param array $values |
||
263 | * @return array |
||
264 | */ |
||
265 | protected function addUpdatedAtColumn(array $values) |
||
276 | |||
277 | /** |
||
278 | * Add the "create_time at" column to an array of values. |
||
279 | * |
||
280 | * @param array $values |
||
281 | * @return array |
||
282 | */ |
||
283 | protected function addInsertedAtColumn(array $values) |
||
294 | |||
295 | |||
296 | /** |
||
297 | * Increment a column's value by a given amount. |
||
298 | * |
||
299 | * @param string $column |
||
300 | * @param int $amount |
||
301 | * @param array $extra |
||
302 | * @return int |
||
303 | */ |
||
304 | public function increment($column, $amount = 1, array $extra = []) |
||
310 | |||
311 | /** |
||
312 | * Delete a record from the database. |
||
313 | * |
||
314 | * @return mixed |
||
315 | */ |
||
316 | public function delete() |
||
320 | |||
321 | /** |
||
322 | * Dynamically handle calls into the query instance. |
||
323 | * |
||
324 | * @param string $method |
||
325 | * @param array $parameters |
||
326 | * @return mixed |
||
327 | */ |
||
328 | public function __call($method, $parameters) |
||
336 | |||
337 | /** |
||
338 | * Force a clone of the underlying query builder when cloning. |
||
339 | * |
||
340 | * @return void |
||
341 | */ |
||
342 | public function __clone() |
||
346 | } |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.