CommonServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
ccs 2
cts 2
cp 1
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
3
4
namespace OpenTribes\Core\Silex\Provider;
5
6
7
use Silex\Application;
8
use Silex\ServiceProviderInterface;
9
use Symfony\Component\Translation\IdentityTranslator;
10
use Symfony\Component\Validator\ConstraintValidatorFactory;
11
use Symfony\Component\Validator\Context\ExecutionContextFactory;
12
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
13
use Symfony\Component\Validator\Validator\RecursiveValidator;
14
15
class CommonServiceProvider implements ServiceProviderInterface{
16
    /**
17
     * Registers services on the given app.
18
     *
19
     * This method should only be used to configure services and parameters.
20
     * It should not get services.
21
     */
22
    public function register(Application $app)
23
    {
24 35
        $app['validator'] = $app->share(function ($app) {
25 25
            if (isset($app['translator'])) {
26
                $r = new \ReflectionClass('Symfony\Component\Validator\Validator');
27
                $file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
28
                if (file_exists($file)) {
29
                    $app['translator']->addResource('xliff', $file, $app['locale'], 'validators');
30
                }
31 1
            }
32 25
            $translator = isset($app['translator']) ? $app['translator'] : new IdentityTranslator();
33
34 25
            $executionContext = new ExecutionContextFactory($translator);
35 25
            $metaDataFactory = new LazyLoadingMetadataFactory();
36 25
            $constrainValidator = new ConstraintValidatorFactory();
37 25
            return new RecursiveValidator($executionContext,$metaDataFactory,$constrainValidator);
38
39
40 35
        });
41 35
    }
42
43
    /**
44
     * Bootstraps the application.
45
     *
46
     * This method is called after all services are registered
47
     * and should be used for "dynamic" configuration (whenever
48
     * a service must be requested).
49
     */
50 35
    public function boot(Application $app)
51
    {
52
53 35
    }
54
55
}