-
Notifications
You must be signed in to change notification settings - Fork 68
/
ArrayRule.php
52 lines (43 loc) · 986 Bytes
/
ArrayRule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Illuminate\Validation\Rules;
use Illuminate\Contracts\Support\Arrayable;
use Stringable;
use function Illuminate\Support\enum_value;
class ArrayRule implements Stringable
{
/**
* The accepted keys.
*
* @var array
*/
protected $keys;
/**
* Create a new array rule instance.
*
* @param array|null $keys
* @return void
*/
public function __construct($keys = null)
{
if ($keys instanceof Arrayable) {
$keys = $keys->toArray();
}
$this->keys = is_array($keys) ? $keys : func_get_args();
}
/**
* Convert the rule to a validation string.
*
* @return string
*/
public function __toString()
{
if (empty($this->keys)) {
return 'array';
}
$keys = array_map(
static fn ($key) => enum_value($key),
$this->keys,
);
return 'array:'.implode(',', $keys);
}
}