Completed
Push — master ( 23bc34...6717d0 )
by Zlatin
02:26
created

MediaServiceProvider::register()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 23
rs 9.0856
cc 3
eloc 12
nc 4
nop 1
1
<?php
2
3
namespace Media;
4
5
use Silex\Application;
6
use Silex\ServiceProviderInterface;
7
use Media\Exception\InvalidConfigurationException;
8
9
class MediaServiceProvider implements ServiceProviderInterface
10
{
11
12
    public function boot(Application $app)
13
    {
14
        
15
        if (!$app->offsetExists('upload.path')) {
16
            throw new InvalidConfigurationException;
17
        }
18
        
19
    }
20
21
    public function register(Application $app)
22
    {
23
24
        if ($app->offsetExists('form.factory')) {
25
            $app['form.types'] = $app->share($app->extend('form.types', function ($types) use ($app) {
26
                        $types[] = new Form\Type\MediaType($app);
27
                        return $types;
28
                    }));
29
        }
30
31
        if ($app->offsetExists('twig')) {
32
            $app['twig'] = $app->share($app->extend('twig', function(\Twig_Environment $twig) use ($app) {
33
                        $twig->addExtension(new Twig\MediaExtension($app));
34
                        return $twig;
35
                    }));
36
37
            $app['twig.path'] = array_merge($app['twig.path'], array(
38
                __DIR__ . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'views'
39
            ));
40
41
            $app['twig.form.templates'] = array_merge($app['twig.form.templates'], array("media.type.html.twig"));
42
        }
43
    }
44
45
}
46