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) |
||
118 | |||
119 | /** |
||
120 | * updateOrInsert |
||
121 | * |
||
122 | * @param $values |
||
123 | * @return bool |
||
124 | */ |
||
125 | public function updateOrInsert($values) |
||
129 | |||
130 | /** |
||
131 | * Get a single column's value from the first result of a query. |
||
132 | * |
||
133 | * @param string $column |
||
134 | * @return mixed |
||
135 | */ |
||
136 | public function value($column) |
||
142 | |||
143 | /** |
||
144 | * Execute the query as a "select" statement. |
||
145 | * |
||
146 | * @param array $columns |
||
147 | * @return \Childish\support\Collection|static[]\ |
||
148 | */ |
||
149 | public function get($columns = ['*']) |
||
153 | |||
154 | /** |
||
155 | * Get the hydrated models without eager loading. |
||
156 | * |
||
157 | * @param array $columns |
||
158 | * @return \Childish\ChildishModel[] |
||
159 | */ |
||
160 | public function getModels($columns = ['*']) |
||
166 | |||
167 | /** |
||
168 | * Create a collection of models from plain arrays. |
||
169 | * |
||
170 | * @param array $items |
||
171 | * @return \Childish\support\Collection |
||
172 | */ |
||
173 | public function hydrate(array $items) |
||
181 | |||
182 | /** |
||
183 | * Create a new instance of the model being queried. |
||
184 | * |
||
185 | * @param array $attributes |
||
186 | * @return \Childish\ChildishModel |
||
187 | */ |
||
188 | public function newModelInstance($attributes = []) |
||
194 | |||
195 | |||
196 | /** |
||
197 | * Execute the query and get the first result. |
||
198 | * |
||
199 | * @param array $columns |
||
200 | * @return \Childish\ChildishModel|static|null |
||
201 | */ |
||
202 | public function first($columns = ['*']) |
||
206 | |||
207 | /** |
||
208 | * Alias to set the "limit" value of the query. |
||
209 | * |
||
210 | * @param int $value |
||
211 | * @return \Childish\query\Builder|static |
||
212 | */ |
||
213 | public function take($value) |
||
217 | |||
218 | /** |
||
219 | * Set the "limit" value of the query. |
||
220 | * |
||
221 | * @param int $value |
||
222 | * @return $this |
||
223 | */ |
||
224 | public function limit($value) |
||
234 | |||
235 | |||
236 | /** |
||
237 | * Get the underlying query builder instance. |
||
238 | * |
||
239 | * @return \Childish\query\Builder |
||
240 | */ |
||
241 | public function getQuery() |
||
245 | |||
246 | /** |
||
247 | * Set the underlying query builder instance. |
||
248 | * |
||
249 | * @param \Childish\query\Builder $query |
||
250 | * @return $this |
||
251 | */ |
||
252 | public function setQuery($query) |
||
258 | |||
259 | |||
260 | /** |
||
261 | * Add the "updated at" column to an array of values. |
||
262 | * |
||
263 | * @param array $values |
||
264 | * @return array |
||
265 | */ |
||
266 | protected function addUpdatedAtColumn(array $values) |
||
277 | |||
278 | /** |
||
279 | * Add the "create_time at" column to an array of values. |
||
280 | * |
||
281 | * @param array $values |
||
282 | * @return array |
||
283 | */ |
||
284 | protected function addInsertedAtColumn(array $values) |
||
295 | |||
296 | |||
297 | /** |
||
298 | * Increment a column's value by a given amount. |
||
299 | * |
||
300 | * @param string $column |
||
301 | * @param int $amount |
||
302 | * @param array $extra |
||
303 | * @return int |
||
304 | */ |
||
305 | public function increment($column, $amount = 1, array $extra = []) |
||
311 | |||
312 | /** |
||
313 | * Delete a record from the database. |
||
314 | * |
||
315 | * @return mixed |
||
316 | */ |
||
317 | public function delete() |
||
321 | |||
322 | /** |
||
323 | * Dynamically handle calls into the query instance. |
||
324 | * |
||
325 | * @param string $method |
||
326 | * @param array $parameters |
||
327 | * @return mixed |
||
328 | */ |
||
329 | public function __call($method, $parameters) |
||
337 | |||
338 | /** |
||
339 | * Force a clone of the underlying query builder when cloning. |
||
340 | * |
||
341 | * @return void |
||
342 | */ |
||
343 | public function __clone() |
||
347 | } |
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.