1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\MediaLibraryPro\Rules; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Validation\Rule; |
6
|
|
|
use Illuminate\Support\Arr; |
7
|
|
|
use Spatie\MediaLibraryPro\Rules\GroupRules\MaxItemsRule; |
8
|
|
|
use Spatie\MediaLibraryPro\Rules\GroupRules\MaxTotalSizeInKbRule; |
9
|
|
|
use Spatie\MediaLibraryPro\Rules\GroupRules\MinItemsRule; |
10
|
|
|
use Spatie\MediaLibraryPro\Rules\GroupRules\MinTotalSizeInKbRule; |
11
|
|
|
use Spatie\MediaLibraryPro\Rules\ItemRules\AttributeRule; |
12
|
|
|
use Spatie\MediaLibraryPro\Rules\ItemRules\DimensionsRule; |
13
|
|
|
use Spatie\MediaLibraryPro\Rules\ItemRules\ExtensionRule; |
14
|
|
|
use Spatie\MediaLibraryPro\Rules\ItemRules\HeightBetweenRule; |
15
|
|
|
use Spatie\MediaLibraryPro\Rules\ItemRules\MaxItemSizeInKbRule; |
16
|
|
|
use Spatie\MediaLibraryPro\Rules\ItemRules\MimeTypeRule; |
17
|
|
|
use Spatie\MediaLibraryPro\Rules\ItemRules\MinItemSizeInKbRule; |
18
|
|
|
use Spatie\MediaLibraryPro\Rules\ItemRules\WidthBetweenRule; |
19
|
|
|
|
20
|
|
|
class UploadedMediaRules implements Rule |
21
|
|
|
{ |
22
|
|
|
public array $groupRules = []; |
23
|
|
|
|
24
|
|
|
public array $itemRules = []; |
25
|
|
|
|
26
|
|
|
public function minItems(int $numberOfItems): self |
27
|
|
|
{ |
28
|
|
|
$this->groupRules[] = new MinItemsRule($numberOfItems); |
29
|
|
|
|
30
|
|
|
return $this; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function maxItems(int $numberOfItems): self |
34
|
|
|
{ |
35
|
|
|
$this->groupRules[] = new MaxItemsRule($numberOfItems); |
36
|
|
|
|
37
|
|
|
return $this; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function maxTotalSizeInKb(int $maxTotalSizeInKb): self |
41
|
|
|
{ |
42
|
|
|
$this->groupRules[] = new MaxTotalSizeInKbRule($maxTotalSizeInKb); |
43
|
|
|
|
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function minTotalSizeInKb(int $minTotalSizeInKb): self |
48
|
|
|
{ |
49
|
|
|
$this->groupRules[] = new MinTotalSizeInKbRule($minTotalSizeInKb); |
50
|
|
|
|
51
|
|
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function maxItemSizeInKb(int $maxSizeInKb): self |
55
|
|
|
{ |
56
|
|
|
$this->itemRules[] = new MaxItemSizeInKbRule($maxSizeInKb); |
57
|
|
|
|
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function minSizeInKb(int $minSizeInKb): self |
62
|
|
|
{ |
63
|
|
|
$this->itemRules[] = new MinItemSizeInKbRule($minSizeInKb); |
64
|
|
|
|
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** @var string|array */ |
69
|
|
|
public function mime($mimes): self |
70
|
|
|
{ |
71
|
|
|
$this->itemRules[] = new MimeTypeRule($mimes); |
72
|
|
|
|
73
|
|
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var string|array |
78
|
|
|
*/ |
79
|
|
|
public function extension($extensions): self |
80
|
|
|
{ |
81
|
|
|
$this->itemRules[] = new ExtensionRule($extensions); |
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function itemName($rules): self |
87
|
|
|
{ |
88
|
|
|
return $this->attribute('name', $rules); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function attribute(string $attribute, array|string $rules): self |
92
|
|
|
{ |
93
|
|
|
$this->itemRules[] = new AttributeRule($attribute, $rules); |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function customProperty(string $customPropertyName, $rules): self |
99
|
|
|
{ |
100
|
|
|
$customPropertyName = "custom_properties.{$customPropertyName}"; |
101
|
|
|
|
102
|
|
|
$this->itemRules[] = new AttributeRule($customPropertyName, $rules); |
103
|
|
|
|
104
|
|
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function dimensions(int $width, int $height): self |
108
|
|
|
{ |
109
|
|
|
$this->itemRules[] = new DimensionsRule($width, $height); |
110
|
|
|
|
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function width(int $width): self |
115
|
|
|
{ |
116
|
|
|
$this->itemRules[] = new DimensionsRule($width, 0); |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function height(int $height): self |
122
|
|
|
{ |
123
|
|
|
$this->itemRules[] = new DimensionsRule(0, $height); |
124
|
|
|
|
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function widthBetween(int $minWidth, int $maxWidth): self |
129
|
|
|
{ |
130
|
|
|
$this->itemRules[] = new WidthBetweenRule($minWidth, $maxWidth); |
131
|
|
|
|
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function heightBetween(int $minHeight, int $maxHeight): self |
136
|
|
|
{ |
137
|
|
|
$this->itemRules[] = new HeightBetweenRule($minHeight, $maxHeight); |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function customItemRules($rules) |
143
|
|
|
{ |
144
|
|
|
$this->itemRules = array_merge($this->itemRules, Arr::wrap($rules)); |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function customGroupRules($rules) |
150
|
|
|
{ |
151
|
|
|
$this->groupRules = array_merge($this->groupRules, Arr::wrap($rules)); |
152
|
|
|
|
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function passes($attribute, $value) |
157
|
|
|
{ |
158
|
|
|
// this page has been left intentionally blank |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function message() |
162
|
|
|
{ |
163
|
|
|
// this page has been left intentionally blank |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|