1 | <?php |
||
18 | class Repository |
||
19 | { |
||
20 | use Filters; |
||
21 | use IncludesRelations; |
||
22 | use Sorts; |
||
23 | use WrapsInResource; |
||
24 | |||
25 | const WITH_ALLOW_ALL = ['*']; |
||
26 | const WITH_ALLOW_NONE = []; |
||
27 | |||
28 | /** @var string */ |
||
29 | protected $model; |
||
30 | |||
31 | /** @var string */ |
||
32 | protected $resource; |
||
33 | |||
34 | /** @var string */ |
||
35 | protected $resource_collection; |
||
36 | |||
37 | /** @var ResourceContext $resource_context */ |
||
38 | protected $resource_context; |
||
39 | |||
40 | /** @var array $allowed_with */ |
||
41 | protected $allowed_with = self::WITH_ALLOW_NONE; |
||
42 | |||
43 | /** @var array $default_with */ |
||
44 | protected $default_with = []; |
||
45 | |||
46 | /** @var string $default_sort_by */ |
||
47 | protected $default_sort_by; |
||
48 | |||
49 | /** @var string $default_sort_order */ |
||
50 | protected $default_sort_order = 'asc'; |
||
51 | |||
52 | public function __construct(ResourceContext $resource_context) |
||
56 | |||
57 | /** |
||
58 | * Creates a new repository for a model. |
||
59 | */ |
||
60 | public static function for(string $model, ResourceContext $context = null): self |
||
69 | |||
70 | public function __call($name, $arguments) |
||
84 | |||
85 | /** |
||
86 | * Get the currenct resource context |
||
87 | */ |
||
88 | public function getContext(): ResourceContext |
||
92 | |||
93 | /** |
||
94 | * Set or replace the resource context |
||
95 | */ |
||
96 | public function setContext(ResourceContext $resource_context) |
||
102 | |||
103 | /** |
||
104 | * Set the model |
||
105 | */ |
||
106 | public function setModel(string $model) |
||
112 | |||
113 | /** |
||
114 | * Return all models based on resource context and query |
||
115 | * |
||
116 | * The ResourceContext determines if the result is a Collection or a |
||
117 | * LengthAwarePaginator. |
||
118 | * |
||
119 | * @return LengthAwarePaginator|Collection |
||
120 | */ |
||
121 | public function all($query = null) |
||
132 | |||
133 | /** |
||
134 | * Produces a result suitable for selects, lists, and autocomplete. All |
||
135 | * entries that has a 'value' and a 'label' key. |
||
136 | * |
||
137 | * Note: if a callable is used the mapping is performed in memory, while a |
||
138 | * string is done in the database layer. |
||
139 | * |
||
140 | * @param callable|string $column |
||
141 | * @param Builder $query |
||
142 | * @return Collection |
||
143 | */ |
||
144 | public function list($column = null, $query = null) |
||
180 | |||
181 | public function find($id, $query = null): Model |
||
193 | |||
194 | public function create(array $data): Model |
||
198 | |||
199 | public function update(Model $model, array $data): Model |
||
205 | |||
206 | public function destroy(Model $model) |
||
210 | |||
211 | protected function modelQuery($query = null) |
||
215 | |||
216 | protected function validateQurey(Builder $query) |
||
227 | |||
228 | /** |
||
229 | * Execute query |
||
230 | * |
||
231 | * @param Builder $query |
||
232 | * @return LengthAwarePaginator|Collection |
||
233 | */ |
||
234 | private function execute($query) |
||
244 | } |
||
245 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.