1
|
<?php
|
2
|
|
3
|
namespace Illuminate\Validation;
|
4
|
|
5
|
use Illuminate\Support\ServiceProvider;
|
6
|
|
7
|
class ValidationServiceProvider extends ServiceProvider
|
8
|
{
|
9
|
/**
|
10
|
* Indicates if loading of the provider is deferred.
|
11
|
*
|
12
|
* @var bool
|
13
|
*/
|
14
|
protected $defer = true;
|
15
|
|
16
|
/**
|
17
|
* Register the service provider.
|
18
|
*
|
19
|
* @return void
|
20
|
*/
|
21
|
public function register()
|
22
|
{
|
23
|
$this->registerPresenceVerifier();
|
24
|
|
25
|
$this->registerValidationFactory();
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Register the validation factory.
|
30
|
*
|
31
|
* @return void
|
32
|
*/
|
33
|
protected function registerValidationFactory()
|
34
|
{
|
35
|
$this->app->singleton('validator', function ($app) {
|
36
|
$validator = new Factory($app['translator'], $app);
|
37
|
|
38
|
// The validation presence verifier is responsible for determining the existence
|
39
|
// of values in a given data collection, typically a relational database or
|
40
|
// other persistent data stores. And it is used to check for uniqueness.
|
41
|
if (isset($app['validation.presence'])) {
|
42
|
$validator->setPresenceVerifier($app['validation.presence']);
|
43
|
}
|
44
|
|
45
|
return $validator;
|
46
|
});
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Register the database presence verifier.
|
51
|
*
|
52
|
* @return void
|
53
|
*/
|
54
|
protected function registerPresenceVerifier()
|
55
|
{
|
56
|
$this->app->singleton('validation.presence', function ($app) {
|
57
|
return new DatabasePresenceVerifier($app['db']);
|
58
|
});
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* Get the services provided by the provider.
|
63
|
*
|
64
|
* @return array
|
65
|
*/
|
66
|
public function provides()
|
67
|
{
|
68
|
return [
|
69
|
'validator', 'validation.presence',
|
70
|
];
|
71
|
}
|
72
|
}
|