/
SettingsValidator.php
54 lines (45 loc) · 1.33 KB
/
SettingsValidator.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
53
54
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Settings;
use Flarum\Foundation\AbstractValidator;
class SettingsValidator extends AbstractValidator
{
/**
* These rules apply to all attributes.
*
* Entries in the default DB settings table are limited to 65,000
* characters. We validate against this to avoid confusing errors.
*
* @var array
*/
protected $globalRules = [
'max:65000',
];
/**
* Make a new validator instance for this model.
*
* @param array $attributes
* @return \Illuminate\Validation\Validator
*/
protected function makeValidator(array $attributes)
{
// Apply global rules first.
$rules = array_map(function () {
return $this->globalRules;
}, $attributes);
// Apply attribute specific rules.
foreach ($rules as $key => $value) {
$rules[$key] = array_merge($rules[$key], $this->rules[$key] ?? []);
}
$validator = $this->validator->make($attributes, $rules, $this->getMessages());
foreach ($this->configuration as $callable) {
$callable($this, $validator);
}
return $validator;
}
}