1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Cilex framework. |
5
|
|
|
* |
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Cilex\Provider; |
13
|
|
|
|
14
|
|
|
use Pimple\Container; |
15
|
|
|
use Pimple\ServiceProviderInterface; |
16
|
|
|
|
17
|
|
|
use Symfony\Component\Validator\Validator; |
18
|
|
|
use Symfony\Component\Validator\Mapping\ClassMetadataFactory; |
19
|
|
|
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader; |
20
|
|
|
use Symfony\Component\Validator\ConstraintValidatorFactory; |
21
|
|
|
use Symfony\Component\Validator\DefaultTranslator; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Symfony Validator component Provider. |
25
|
|
|
* |
26
|
|
|
* This class is an adaptation of the Silex MonologServiceProvider written by |
27
|
|
|
* Fabien Potencier. |
28
|
|
|
* |
29
|
|
|
* @author Fabien Potencier <[email protected]> |
30
|
|
|
* @author Mike van Riel <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class ValidatorServiceProvider implements ServiceProviderInterface |
33
|
|
|
{ |
34
|
|
|
public function register(Container $app) |
35
|
|
|
{ |
36
|
|
|
$app['validator'] = function ($app) { |
37
|
|
|
return new Validator( |
|
|
|
|
38
|
|
|
$app['validator.mapping.class_metadata_factory'], |
39
|
|
|
$app['validator.validator_factory'], |
40
|
|
|
$app['validator.default_translator'] |
41
|
|
|
); |
42
|
|
|
}; |
43
|
|
|
|
44
|
|
|
$app['validator.mapping.class_metadata_factory'] = function () { |
45
|
|
|
return new ClassMetadataFactory(new StaticMethodLoader()); |
|
|
|
|
46
|
|
|
}; |
47
|
|
|
|
48
|
|
|
$app['validator.validator_factory'] = function () { |
49
|
|
|
return new ConstraintValidatorFactory(); |
50
|
|
|
}; |
51
|
|
|
|
52
|
|
|
$app['validator.default_translator'] = function () { |
53
|
|
|
if (!class_exists('Symfony\\Component\\Validator\\DefaultTranslator')) { |
54
|
|
|
return array(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return new DefaultTranslator(); |
|
|
|
|
58
|
|
|
}; |
59
|
|
|
|
60
|
|
|
if (isset($app['validator.class_path'])) { |
61
|
|
|
$app['autoloader']->registerNamespace('Symfony\\Component\\Validator', $app['validator.class_path']); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.