CalendRServiceProvider::boot()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.2222
c 0
b 0
f 0
cc 6
nc 4
nop 1
1
<?php
2
3
namespace CalendR\Extension\Silex\Provider;
4
5
use CalendR\Calendar;
6
use CalendR\Event\Manager;
7
use CalendR\Bridge\Twig\CalendRExtension;
8
use Silex\Application;
9
use Silex\ServiceProviderInterface;
10
11
/**
12
 * Silex CalendR Service Provider.
13
 *
14
 * @deprecated since 2.1, will be removed in 3.0 as silex isn't maintained anymore
15
 *
16
 * @author Yohan Giarelli<[email protected]>
17
 */
18
class CalendRServiceProvider implements ServiceProviderInterface
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function register(Application $app)
24
    {
25
        @trigger_error('The silex service provider is deprecated since 2.1 as Silex isn’t maintained anymore', E_USER_DEPRECATED);
26
27
        $app['calendr'] = $app->share(function ($app) {
28
            $calendr = new Calendar();
29
            $calendr->setEventManager($app['calendr.event_manager']);
30
31
            return $calendr;
32
        });
33
34
        $app['calendr.event_manager'] = $app->share(function ($app) {
35
            return new Manager(
36
                isset($app['calendr.event.providers']) ? $app['calendr.event.providers'] : array(),
37
                isset($app['calendr.event.collection.instantiator']) ? $app['calendr.event.collection.instantiator'] : null
38
            );
39
        });
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function boot(Application $app)
46
    {
47
        if (class_exists('Twig_Environment')) {
48
            $extension = new CalendRExtension($app['calendr']);
49
            if (isset($app['calendr.twig']) && 'Twig_Environment' == get_class($app['calendr.twig'])) {
50
                $app['calendr.twig']->addExtension($extension);
51
            } elseif (isset($app['twig']) && 'Twig_Environment' == get_class($app['twig'])) {
52
                $app['twig']->addExtension($extension);
53
            }
54
        }
55
    }
56
}
57