Completed
Push — develop ( c7d805...cd170e )
by Jaap
04:24
created

ValidatorServiceProvider::register()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 16
nc 2
nop 1
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
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(
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Validator\Validator has been deprecated with message: since version 2.5, to be removed in 3.0. Use {@link Validator\RecursiveValidator} instead.

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.

Loading history...
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());
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Valida...ng\ClassMetadataFactory has been deprecated with message: since version 2.5, to be removed in 3.0. Use {@link LazyLoadingMetadataFactory} instead.

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.

Loading history...
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();
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Component\Validator\DefaultTranslator has been deprecated with message: since version 2.7, to be removed in 3.0. Use Symfony\Component\Translation\IdentityTranslator instead.

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.

Loading history...
58
        };
59
60
        if (isset($app['validator.class_path'])) {
61
            $app['autoloader']->registerNamespace('Symfony\\Component\\Validator', $app['validator.class_path']);
62
        }
63
    }
64
}
65