1 | <?php |
||
2 | |||
3 | namespace Arbory\Base\Admin\Filter\Parameters; |
||
4 | |||
5 | use Illuminate\Support\Arr; |
||
6 | use Arbory\Base\Support\ExtendedFluent; |
||
7 | use Arbory\Base\Admin\Filter\FilterItem; |
||
8 | |||
9 | class FilterParameters extends ExtendedFluent |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $namespace = 'filter'; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $errors = []; |
||
20 | |||
21 | /** |
||
22 | * @return string |
||
23 | */ |
||
24 | public function getNamespace(): ?string |
||
25 | { |
||
26 | return $this->namespace; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param string|null $namespace |
||
31 | * @return FilterParameters |
||
32 | */ |
||
33 | public function setNamespace(?string $namespace): self |
||
34 | { |
||
35 | $this->namespace = $namespace; |
||
36 | |||
37 | return $this; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param FilterItem $filterItem |
||
42 | * @return mixed |
||
43 | */ |
||
44 | public function getFromFilter(FilterItem $filterItem) |
||
45 | { |
||
46 | return $this->get($filterItem->getName()); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string|null $fieldName |
||
51 | * @return array |
||
52 | */ |
||
53 | public function getErrors(?string $fieldName = null): array |
||
54 | { |
||
55 | if ($fieldName !== null) { |
||
56 | return Arr::get($this->errors, $fieldName); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
57 | } |
||
58 | |||
59 | return $this->errors; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param array $errors |
||
64 | * @return FilterParameters |
||
65 | */ |
||
66 | public function setErrors(array $errors): self |
||
67 | { |
||
68 | $this->errors = $errors; |
||
69 | |||
70 | return $this; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param string $fieldName |
||
75 | * @param array $errors |
||
76 | * @return FilterParameters |
||
77 | */ |
||
78 | public function addErrors(string $fieldName, array $errors): self |
||
79 | { |
||
80 | $this->errors[$fieldName] = $errors; |
||
81 | |||
82 | return $this; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @param string $fieldName |
||
87 | * @return bool |
||
88 | */ |
||
89 | public function hasError(string $fieldName): bool |
||
90 | { |
||
91 | return Arr::has($this->errors, $fieldName); |
||
92 | } |
||
93 | } |
||
94 |