AnnotationServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 7
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A register() 0 17 3
1
<?php
2
/**
3
 * This file is part of the silex-annotation-provider package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @license       MIT License
8
 * @copyright (c) 2018, Dana Desrosiers <[email protected]>
9
 */
10
11
declare(strict_types=1);
12
13
namespace DDesrosiers\SilexAnnotations;
14
15
use DDesrosiers\SilexAnnotations\AnnotationReader\AnnotationReader;
16
use DDesrosiers\SilexAnnotations\Cache\AnnotationCache;
17
use Pimple\Container;
18
use Pimple\ServiceProviderInterface;
19
use Psr\SimpleCache\InvalidArgumentException;
20
use Silex\Api\BootableProviderInterface;
21
use Silex\Application;
22
use Silex\Provider\ServiceControllerServiceProvider;
23
24
/**
25
 * Class AnnotationServiceProvider provides the 'annot' service, an instance of
26
 * AnnotationService.
27
 *
28
 * @author Dana Desrosiers <[email protected]>
29
 */
30
class AnnotationServiceProvider implements ServiceProviderInterface, BootableProviderInterface
31
{
32
    /**
33
     * @param Application $app
34
     * @throws InvalidArgumentException
35
     */
36
    public function boot(Application $app)
37
    {
38
        /** @var AnnotationService $annotationService */
39
        $annotationService = $app['annot'];
40
        $annotationService->registerControllers();
41
    }
42
43
    /**
44
     * @param Container $app
45
     */
46
    public function register(Container $app)
47
    {
48
        $app["annot"] = function (Application $app) {
49
            $cache = (!$app['debug'] && $app->offsetExists('annot.cache')) ? $app['annot.cache'] : null;
50
            return new AnnotationService(
51
                $app,
52
                new ControllerFinder($app['annot.controllerDir'], $app['annot.controllers']),
53
                new AnnotationReader(),
54
                new AnnotationCache($cache));
55
        };
56
57
        $app->register(new ServiceControllerServiceProvider());
58
59
        $app['annot.base_uri'] = '';
60
        $app['annot.controllers'] = [];
61
        $app['annot.controllerDir'] = null;
62
    }
63
}
64