Module::getConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 22
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 9.2
cc 1
eloc 15
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\ZFLinkHeadersModule;
6
7
use Facile\ZFLinkHeadersModule\Listener\LinkHandler;
8
use Facile\ZFLinkHeadersModule\Listener\ScriptHandler;
9
use Facile\ZFLinkHeadersModule\Listener\StylesheetHandler;
10
use Zend\EventManager\EventInterface;
11
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
12
use Zend\ModuleManager\Feature\ConfigProviderInterface;
13
use Zend\Mvc\MvcEvent;
14
15
final class Module implements BootstrapListenerInterface, ConfigProviderInterface
16
{
17
    /**
18
     * @param EventInterface $e
19
     * @return array|void
20
     * @throws \Psr\Container\ContainerExceptionInterface
21
     * @throws \Psr\Container\NotFoundExceptionInterface
22
     */
23 2
    public function onBootstrap(EventInterface $e)
24
    {
25 2
        if (! $e instanceof MvcEvent) {
26 1
            return;
27
        }
28
29 1
        $app = $e->getApplication();
30 1
        $container = $app->getServiceManager();
31 1
        $eventManager = $app->getEventManager();
32
33 1
        $linkHandler = $container->get(LinkHandler::class);
34 1
        $eventManager->attach(MvcEvent::EVENT_FINISH, $linkHandler);
35
36 1
        $stylesheetHandler = $container->get(StylesheetHandler::class);
37 1
        $eventManager->attach(MvcEvent::EVENT_FINISH, $stylesheetHandler);
38
39 1
        $scriptHandler = $container->get(ScriptHandler::class);
40 1
        $eventManager->attach(MvcEvent::EVENT_FINISH, $scriptHandler);
41 1
    }
42
43
    /**
44
     * Returns configuration to merge with application configuration
45
     *
46
     * @return array|\Traversable
47
     */
48 1
    public function getConfig()
49
    {
50
        return [
51 1
            'facile' => [
52
                'zf_link_headers_module' => [
53
                    'stylesheet_enabled' => false,
54
                    'stylesheet_mode' => 'preload',
55
                    'script_enabled' => false,
56
                    'script_mode' => 'preload',
57
                    'http2_push_enabled' => true,
58
                ],
59
            ],
60
            'service_manager' => [
61
                'factories' => [
62
                    OptionsInterface::class => Service\OptionsConfigFactory::class,
63
                    Listener\LinkHandler::class => Listener\LinkHandlerFactory::class,
64
                    Listener\StylesheetHandler::class => Listener\StylesheetHandlerFactory::class,
65
                    Listener\ScriptHandler::class => Listener\ScriptHandlerFactory::class,
66
                ],
67
            ],
68
        ];
69
    }
70
}
71