Completed
Push — master ( 879d36...0a7e57 )
by Thomas Mauro
02:06
created

Module::onBootstrap()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 3

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 32
ccs 21
cts 21
cp 1
rs 8.8571
cc 3
eloc 18
nc 4
nop 1
crap 3
1
<?php
2
3
namespace Facile\SentryModule;
4
5
use Facile\SentryModule\Options\ConfigurationOptions;
6
use Facile\SentryModule\Service\Client;
7
use Facile\SentryModule\Service\ErrorHandlerRegister;
8
use Zend\EventManager\EventInterface;
9
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
10
use Zend\ModuleManager\Feature\ConfigProviderInterface;
11
use Zend\Mvc\MvcEvent;
12
13
/**
14
 * Class Module.
15
 */
16
class Module implements ConfigProviderInterface, BootstrapListenerInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 1
    public function getConfig()
22
    {
23 1
        return include __DIR__.'/../config/module.config.php';
24
    }
25
26
    /**
27
     * Listen to the bootstrap event.
28
     *
29
     * @param EventInterface $e
30
     *
31
     * @return array
32
     *
33
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
34
     * @throws \Zend\ServiceManager\Exception\InvalidServiceException
35
     * @throws \RuntimeException
36
     * @throws \Interop\Container\Exception\NotFoundException
37
     * @throws \Interop\Container\Exception\ContainerException
38
     */
39 2
    public function onBootstrap(EventInterface $e)
40
    {
41
        /* @var MvcEvent $e */
42 2
        $application = $e->getApplication();
43 2
        $container = $application->getServiceManager();
44 2
        $moduleConfig = $container->get('config')['facile']['sentry'];
45 2
        $clients = array_keys($moduleConfig['client']);
46
47 2
        $errorHandlerRegister = $container->get(ErrorHandlerRegister::class);
48
49 2
        foreach ($clients as $serviceKey) {
50 2
            $serviceName = sprintf('facile.sentry.client.%s', $serviceKey);
51
52
            /* @var Client $client */
53 2
            $client = $container->get($serviceName);
54 2
            $errorHandlerRegister->registerHandlers($client, $application->getEventManager());
55 2
        }
56
57 2
        $configurationOptions = $container->get(ConfigurationOptions::class);
58 2
        if (!$configurationOptions->isInjectRavenJavascript()) {
59 1
            return;
60
        }
61
62
        /** @var \Zend\View\HelperPluginManager $viewHelperManager */
63 1
        $viewHelperManager = $container->get('ViewHelperManager');
64
        /** @var \Zend\View\Helper\HeadScript $headScriptHelper */
65 1
        $headScriptHelper = $viewHelperManager->get('HeadScript');
66 1
        $headScriptHelper->appendFile($configurationOptions->getRavenJavascriptUri());
67 1
        $headScriptHelper->appendScript(
68 1
            sprintf('Raven.config(\'%s\').install()', $configurationOptions->getRavenJavascriptDsn())
69 1
        );
70 1
    }
71
}
72