1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Facile\LaminasLinkHeadersModule; |
6
|
|
|
|
7
|
|
|
use Facile\LaminasLinkHeadersModule\Listener\LinkHandler; |
8
|
|
|
use Facile\LaminasLinkHeadersModule\Listener\ScriptHandler; |
9
|
|
|
use Facile\LaminasLinkHeadersModule\Listener\StylesheetHandler; |
10
|
|
|
use Laminas\EventManager\EventInterface; |
11
|
|
|
use Laminas\Mvc\MvcEvent; |
12
|
|
|
|
13
|
|
|
final class Module |
14
|
|
|
{ |
15
|
2 |
|
public function onBootstrap(EventInterface $e): void |
16
|
|
|
{ |
17
|
2 |
|
if (! $e instanceof MvcEvent) { |
18
|
1 |
|
return; |
19
|
|
|
} |
20
|
|
|
|
21
|
1 |
|
$app = $e->getApplication(); |
22
|
1 |
|
$container = $app->getServiceManager(); |
23
|
1 |
|
$eventManager = $app->getEventManager(); |
24
|
|
|
|
25
|
1 |
|
$linkHandler = $container->get(LinkHandler::class); |
26
|
1 |
|
$eventManager->attach(MvcEvent::EVENT_FINISH, $linkHandler); |
27
|
|
|
|
28
|
1 |
|
$stylesheetHandler = $container->get(StylesheetHandler::class); |
29
|
1 |
|
$eventManager->attach(MvcEvent::EVENT_FINISH, $stylesheetHandler); |
30
|
|
|
|
31
|
1 |
|
$scriptHandler = $container->get(ScriptHandler::class); |
32
|
1 |
|
$eventManager->attach(MvcEvent::EVENT_FINISH, $scriptHandler); |
33
|
1 |
|
} |
34
|
|
|
|
35
|
1 |
|
public function getConfig(): array |
36
|
|
|
{ |
37
|
|
|
return [ |
38
|
|
|
'facile' => [ |
39
|
|
|
'laminas_link_headers_module' => [ |
40
|
1 |
|
'stylesheet_enabled' => false, |
41
|
|
|
'stylesheet_mode' => 'preload', |
42
|
|
|
'script_enabled' => false, |
43
|
|
|
'script_mode' => 'preload', |
44
|
|
|
'http2_push_enabled' => true, |
45
|
|
|
], |
46
|
|
|
], |
47
|
|
|
'service_manager' => [ |
48
|
|
|
'factories' => [ |
49
|
|
|
OptionsInterface::class => Service\OptionsConfigFactory::class, |
50
|
|
|
Listener\LinkHandler::class => Listener\LinkHandlerFactory::class, |
51
|
|
|
Listener\StylesheetHandler::class => Listener\StylesheetHandlerFactory::class, |
52
|
|
|
Listener\ScriptHandler::class => Listener\ScriptHandlerFactory::class, |
53
|
|
|
], |
54
|
|
|
], |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|