Completed
Push — master ( 8c4272...ef6d68 )
by Thomas Mauro
11s
created

Module::onBootstrap()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
ccs 14
cts 14
cp 1
rs 8.9713
cc 2
eloc 13
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Facile\SentryModule;
4
5
use Facile\SentryModule\Options\ConfigurationInterface;
6
use Zend\EventManager\EventInterface;
7
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
8
use Zend\ModuleManager\Feature\ConfigProviderInterface;
9
use Zend\Mvc\MvcEvent;
10
11
/**
12
 * Class Module.
13
 */
14
class Module implements ConfigProviderInterface, BootstrapListenerInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function getConfig()
20
    {
21
        return include __DIR__.'/../config/module.config.php';
22
    }
23
24
    /**
25
     * Listen to the bootstrap event.
26
     *
27
     * @param EventInterface $e
28
     *
29
     * @return void
30
     *
31
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
32
     * @throws \Zend\ServiceManager\Exception\InvalidServiceException
33
     * @throws \RuntimeException
34
     * @throws \Interop\Container\Exception\NotFoundException
35
     * @throws \Interop\Container\Exception\ContainerException
36
     */
37 2
    public function onBootstrap(EventInterface $e)
38
    {
39
        /* @var MvcEvent $e */
40 2
        $application = $e->getApplication();
41 2
        $container = $application->getServiceManager();
42
43
        /** @var ConfigurationInterface $configuration */
44 2
        $configuration = $container->get(ConfigurationInterface::class);
45
46 2
        if ($configuration->shouldInjectRavenJavascript()) {
47
            /** @var \Zend\View\HelperPluginManager $viewHelperManager */
48 1
            $viewHelperManager = $container->get('ViewHelperManager');
49
            /** @var \Zend\View\Helper\HeadScript $headScriptHelper */
50 1
            $headScriptHelper = $viewHelperManager->get('HeadScript');
51 1
            $headScriptHelper->appendFile($configuration->getRavenJavascriptUri());
52 1
            $headScriptHelper->appendScript(
53 1
                sprintf(
54 1
                    'Raven.config(\'%s\', %s).install();',
55 1
                    $configuration->getRavenJavascriptDsn(),
56 1
                    json_encode($configuration->getRavenJavascriptOptions())
57
                )
58
            );
59
        }
60 2
    }
61
}
62