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 ResourceContext $resource_context */ |
||
32 | protected $resource_context; |
||
33 | |||
34 | /** @var array $allowed_with */ |
||
35 | protected $allowed_with = self::WITH_ALLOW_NONE; |
||
36 | |||
37 | /** @var array $default_with */ |
||
38 | protected $default_with = []; |
||
39 | |||
40 | /** @var string $default_sort_by */ |
||
41 | protected $default_sort_by; |
||
42 | |||
43 | /** @var string $default_sort_order */ |
||
44 | protected $default_sort_order = 'asc'; |
||
45 | |||
46 | /** @var string|function $list_column */ |
||
47 | protected $default_list_column; |
||
48 | |||
49 | public function __construct(ResourceContext $resource_context) |
||
54 | |||
55 | protected function register() |
||
59 | |||
60 | /** |
||
61 | * Creates a new repository for a model. |
||
62 | */ |
||
63 | public static function for(string $model, ResourceContext $context = null): self |
||
72 | |||
73 | public function __call($name, $arguments) |
||
87 | |||
88 | /** |
||
89 | * Get the currenct resource context |
||
90 | */ |
||
91 | public function getContext(): ResourceContext |
||
95 | |||
96 | /** |
||
97 | * Set or replace the resource context |
||
98 | */ |
||
99 | public function setContext(ResourceContext $resource_context) |
||
105 | |||
106 | /** |
||
107 | * Set the model |
||
108 | */ |
||
109 | public function setModel(string $model) |
||
115 | |||
116 | /** |
||
117 | * Return all models based on resource context and query |
||
118 | * |
||
119 | * The ResourceContext determines if the result is a Collection or a |
||
120 | * LengthAwarePaginator. |
||
121 | * |
||
122 | * @return LengthAwarePaginator|Collection |
||
123 | */ |
||
124 | public function all($query = null) |
||
135 | |||
136 | /** |
||
137 | * Execute query |
||
138 | * |
||
139 | * @param Builder $query |
||
140 | * @return LengthAwarePaginator|Collection |
||
141 | */ |
||
142 | private function execute($query) |
||
152 | |||
153 | /** |
||
154 | * Produces a result suitable for selects, lists, and autocomplete. All |
||
155 | * entries that has a 'value' and a 'label' key. |
||
156 | * |
||
157 | * Note: if a callable is used the mapping is performed in memory, while a |
||
158 | * string is done in the database layer. |
||
159 | * |
||
160 | * @param callable|string $column |
||
161 | * @param Builder $query |
||
162 | * @return Collection |
||
163 | */ |
||
164 | public function list($column = null, $query = null) |
||
202 | |||
203 | public function find($id, $query = null): Model |
||
215 | |||
216 | public function create(array $data): Model |
||
220 | |||
221 | public function update(Model $model, array $data): Model |
||
227 | |||
228 | public function destroy(Model $model) |
||
232 | |||
233 | protected function modelQuery($query = null) |
||
237 | |||
238 | protected function validateQurey(Builder $query) |
||
249 | } |
||
250 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.