-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidationBundle.php
68 lines (58 loc) · 2.28 KB
/
ValidationBundle.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
namespace Pandawa\Bundle\ValidationBundle;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Validation\Factory;
use Illuminate\Validation\ValidationServiceProvider;
use Pandawa\Bundle\DependencyInjectionBundle\Plugin\ImportServicesPlugin;
use Pandawa\Bundle\FoundationBundle\Plugin\ImportConfigurationPlugin;
use Pandawa\Bundle\FoundationBundle\Plugin\RegisterBundlesPlugin;
use Pandawa\Component\Foundation\Application;
use Pandawa\Component\Foundation\Bundle\Bundle;
use Pandawa\Component\Validation\Validator;
use Pandawa\Contracts\Foundation\HasPluginInterface;
use Pandawa\Contracts\Validation\FactoryInterface;
use Pandawa\Contracts\Validation\RuleRegistryInterface;
/**
* @author Iqbal Maulana <iq.bluejack@gmail.com>
*/
class ValidationBundle extends Bundle implements HasPluginInterface, DeferrableProvider
{
const RULE_CONFIG_KEY = 'pandawa.rules';
protected array $deferred = [
'validator',
'validation.parser.resolver',
'validation.rule_registry',
'validation.factory',
RuleRegistryInterface::class,
FactoryInterface::class,
];
public function configure(): void
{
$this->app->singleton('validator', function (Application $app) {
$validator = new Factory($app['translator'], $app);
// The validation presence verifier is responsible for determining the existence of
// values in a given data collection which is typically a relational database or
// other persistent data stores. It is used to check for "uniqueness" as well.
if (isset($app['db'], $app['validation.presence'])) {
$validator->setPresenceVerifier($app['validation.presence']);
}
$validator->resolver(fn($translator, $data, $rules, $messages, $customAttributes) => new Validator(
$translator,
$data,
$rules,
$messages,
$customAttributes
));
return $validator;
});
}
public function plugins(): array
{
return [
new RegisterBundlesPlugin([ValidationServiceProvider::class]),
new ImportConfigurationPlugin(),
new ImportServicesPlugin(),
];
}
}