1 | <?php |
||
13 | class Repository |
||
14 | { |
||
15 | use Filters; |
||
16 | use IncludesRelations; |
||
17 | use Sorts; |
||
18 | |||
19 | const WITH_ALLOW_ALL = ['*']; |
||
20 | const WITH_ALLOW_NONE = []; |
||
21 | |||
22 | /** @var string */ |
||
23 | protected $model; |
||
24 | |||
25 | /** @var ResourceContext $resource_context */ |
||
26 | protected $resource_context; |
||
27 | |||
28 | /** @var array $allowed_with */ |
||
29 | protected $allowed_with = self::WITH_ALLOW_NONE; |
||
30 | |||
31 | /** @var array $default_with */ |
||
32 | protected $default_with = []; |
||
33 | |||
34 | /** @var string $default_sort_by */ |
||
35 | protected $default_sort_by; |
||
36 | |||
37 | /** @var string $default_sort_order */ |
||
38 | protected $default_sort_order = 'asc'; |
||
39 | |||
40 | public function __construct(ResourceContext $resource_context) |
||
44 | |||
45 | /** |
||
46 | * Creates a new repository for a model. |
||
47 | */ |
||
48 | public static function for(string $model, ResourceContext $context = null): self |
||
57 | |||
58 | /** |
||
59 | * Get the currenct resource context |
||
60 | */ |
||
61 | public function getContext(): ResourceContext |
||
65 | |||
66 | /** |
||
67 | * Set or replace the resource context |
||
68 | */ |
||
69 | public function setContext(ResourceContext $resource_context) |
||
75 | |||
76 | /** |
||
77 | * Set the model |
||
78 | */ |
||
79 | public function setModel(string $model) |
||
85 | |||
86 | /** |
||
87 | * Return all models based on resource context and query |
||
88 | * |
||
89 | * The ResourceContext determines if the result is a Collection or a |
||
90 | * Paginator. |
||
91 | * |
||
92 | * @return LengthAwarePaginator|Collection |
||
93 | */ |
||
94 | public function all($query = null) |
||
105 | |||
106 | public function find($id, $query = null): Model |
||
118 | |||
119 | public function create(array $data): Model |
||
123 | |||
124 | public function update(Model $model, array $data): Model |
||
129 | |||
130 | public function destroy(Model $model) |
||
134 | |||
135 | protected function modelQuery($query = null) |
||
139 | |||
140 | protected function validateQurey(Builder $query) |
||
151 | |||
152 | /** |
||
153 | * @param Builder $query |
||
154 | * @return LengthAwarePaginator|Collection |
||
155 | */ |
||
156 | private function paginate($query) |
||
166 | } |
||
167 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.