forked from EvanDotPro/EdpSuperluminal
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Module.php
55 lines (47 loc) · 1.9 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace EdpSuperluminal;
use Zend\Console\Request as ConsoleRequest;
use Zend\Mvc\MvcEvent;
/**
* Create a class cache of all classes used.
*
* @package EdpSuperluminal
*/
class Module
{
/**
* Attach the cache event listener
*
* @param MvcEvent $e
*/
public function onBootstrap(MvcEvent $e)
{
$serviceManager = $e->getApplication()->getServiceManager();
/** @var CacheBuilder $cacheBuilder */
$cacheBuilder = $serviceManager->get('EdpSuperluminal\CacheBuilder');
$eventManager = $e->getApplication()->getEventManager()->getSharedManager();
$eventManager->attach('Zend\Mvc\Application', 'finish', function (MvcEvent $e) use ($cacheBuilder) {
$request = $e->getRequest();
if ($request instanceof ConsoleRequest ||
$request->getQuery()->get('EDPSUPERLUMINAL_CACHE', null) === null) {
return;
}
$cacheBuilder->cache(ZF_CLASS_CACHE);
});
}
public function getServiceConfig()
{
return array(
'invokables' => array(
'EdpSuperluminal\ClassDeclaration\UseStatementService' => 'EdpSuperluminal\ClassDeclaration\FileReflectionUseStatementService',
),
'factories' => array(
'EdpSuperluminal\CacheCodeGenerator' => 'EdpSuperluminal\CacheCodeGeneratorFactory',
'EdpSuperluminal\CacheBuilder' => 'EdpSuperluminal\CacheBuilderFactory',
'EdpSuperluminal\ShouldCacheClass' => 'EdpSuperluminal\ShouldCacheClass\ShouldCacheClassSpecificationFactory',
'EdpSuperluminal\ClassDeclarationService' => 'EdpSuperluminal\ClassDeclaration\ClassDeclarationServiceFactory',
'EdpSuperluminal\ClassDeclaration\ClassUseNameService' => 'EdpSuperluminal\ClassDeclaration\ClassUseNameServiceFactory',
)
);
}
}