|
9 | 9 | use Illuminate\Support\Traits\Macroable; |
10 | 10 | use Illuminate\Database\Eloquent\Builder; |
11 | 11 | use Kettasoft\Filterable\Foundation\Invoker; |
| 12 | +use Kettasoft\Filterable\Contracts\Commitable; |
12 | 13 | use Kettasoft\Filterable\Foundation\Resources; |
13 | 14 | use Kettasoft\Filterable\Contracts\Validatable; |
14 | 15 | use Kettasoft\Filterable\Contracts\Authorizable; |
15 | 16 | use Kettasoft\Filterable\Sanitization\Sanitizer; |
| 17 | +use Kettasoft\Filterable\Engines\Foundation\Clause; |
16 | 18 | use Kettasoft\Filterable\Engines\Foundation\Engine; |
17 | 19 | use Kettasoft\Filterable\Foundation\Sorting\Sorter; |
18 | 20 | use Kettasoft\Filterable\Contracts\FilterableContext; |
|
21 | 23 | use Kettasoft\Filterable\Foundation\FilterableSettings; |
22 | 24 | use Kettasoft\Filterable\Exceptions\MissingBuilderException; |
23 | 25 | use Kettasoft\Filterable\Engines\Foundation\Executors\Executer; |
| 26 | +use Kettasoft\Filterable\Foundation\Contracts\FilterableProfile; |
24 | 27 | use Kettasoft\Filterable\Foundation\Contracts\Sorting\Invokable; |
| 28 | +use Kettasoft\Filterable\Foundation\Events\Contracts\EventManager; |
25 | 29 | use Kettasoft\Filterable\Foundation\Events\FilterableEventManager; |
26 | 30 | use Kettasoft\Filterable\HttpIntegration\HeaderDrivenEngineSelector; |
27 | 31 | use Kettasoft\Filterable\Foundation\Contracts\ShouldReturnQueryBuilder; |
28 | 32 | use Kettasoft\Filterable\Exceptions\RequestSourceIsNotSupportedException; |
29 | | -use Kettasoft\Filterable\Foundation\Contracts\FilterableProfile; |
30 | | -use Kettasoft\Filterable\Foundation\Events\Contracts\EventManager; |
31 | 33 |
|
32 | | -class Filterable implements FilterableContext, Authorizable, Validatable |
| 34 | +class Filterable implements FilterableContext, Authorizable, Validatable, Commitable |
33 | 35 | { |
34 | 36 | use Traits\InteractsWithFilterKey, |
35 | 37 | Traits\InteractsWithMethodMentoring, |
@@ -154,6 +156,12 @@ class Filterable implements FilterableContext, Authorizable, Validatable |
154 | 156 | */ |
155 | 157 | protected static EventManager $eventManager; |
156 | 158 |
|
| 159 | + /** |
| 160 | + * Applied clauses. |
| 161 | + * @var array |
| 162 | + */ |
| 163 | + protected $applied = []; |
| 164 | + |
157 | 165 | /** |
158 | 166 | * Create a new Filterable instance. |
159 | 167 | * @param Request|null $request |
@@ -257,6 +265,34 @@ public function useProfile(FilterableProfile|callable|string $profile): static |
257 | 265 | return $this; |
258 | 266 | } |
259 | 267 |
|
| 268 | + /** |
| 269 | + * Commit clause. |
| 270 | + * |
| 271 | + * @param string $key |
| 272 | + * @param Clause $clause |
| 273 | + * @return bool |
| 274 | + */ |
| 275 | + public function commit(string $key, Clause $clause): bool |
| 276 | + { |
| 277 | + $this->applied[$key] = $clause; |
| 278 | + return true; |
| 279 | + } |
| 280 | + |
| 281 | + /** |
| 282 | + * Get applied clauses. |
| 283 | + * |
| 284 | + * @param string $key |
| 285 | + * @return array|Clause|null |
| 286 | + */ |
| 287 | + public function applied($key = null) |
| 288 | + { |
| 289 | + if (!$key) { |
| 290 | + return $this->applied; |
| 291 | + } |
| 292 | + |
| 293 | + return $this->applied[$key] ?? null; |
| 294 | + } |
| 295 | + |
260 | 296 | /** |
261 | 297 | * Register the event manager instance. |
262 | 298 | * @param array $options |
|
0 commit comments