-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
executable file
·127 lines (108 loc) · 4.03 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace AtPhpSettings;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\Mvc\MvcEvent;
class Module implements
AutoloaderProviderInterface,
ConfigProviderInterface
{
/**
* Configure PHP ini settings
*
* @param \Zend\Mvc\MvcEvent $e
*/
public function onBootstrap(MvcEvent $e)
{
$application = $e->getParam('application');
$config = $application->getConfig();
$phpSettings = $config['php_settings'];
if ($phpSettings) {
$events = $application->getEventManager();
$events->attach('route', array($this, 'applyPhpSettings'));
}
}
public function applyPhpSettings(MvcEvent $e)
{
$application = $e->getApplication();
$config = $application->getConfig();
$matches = $e->getRouteMatch();
$phpSettings = $config['php_settings'];
// Check for controller-specific php settings
if (isset($phpSettings['controllers']) && is_array($phpSettings['controllers'])) {
$controller = $matches->getParam('controller');
$controllerPhpSettings = $phpSettings['controllers'];
if (isset($controllerPhpSettings[$controller]) && is_array($controllerPhpSettings[$controller])) {
$phpSettings = array_merge($phpSettings, $controllerPhpSettings[$controller]);
}
}
// Check for route-specific php settings
if (isset($phpSettings['routes']) && is_array($phpSettings['routes'])) {
$route = $matches->getMatchedRouteName();
$routePhpSettings = $phpSettings['routes'];
if (isset($routePhpSettings[$route]) && is_array($routePhpSettings[$route])) {
$phpSettings = array_merge($phpSettings, $routePhpSettings[$route]);
}
}
foreach ($phpSettings as $key => $value) {
if (!is_array($value)) {
ini_set($key, $value);
}
}
}
/**
* @see http://www.php.net/manual/en/ini.list.php
* @return array
*/
public function getConfig()
{
return array(
'service_manager' => array(
'invokables' => array(
'AtPhpSettings\Collector\PhpSettingsCollector' => 'AtPhpSettings\Collector\PhpSettingsCollector',
),
),
'view_manager' => array(
'template_map' => array(
'zend-developer-tools/toolbar/at-php-settings' => __DIR__ . '/view/zend-developer-tools/toolbar/at-php-settings.phtml'
)
),
'zenddevelopertools' => array(
'profiler' => array(
'collectors' => array(
'at_php_settings' => 'AtPhpSettings\Collector\PhpSettingsCollector',
),
),
'toolbar' => array(
'entries' => array(
'at_php_settings' => 'zend-developer-tools/toolbar/at-php-settings',
),
),
),
'php_settings' => array(
// Global php settings
'display_startup_errors' => false,
'display_errors' => false,
'max_execution_time' => 30,
'date.timezone' => 'UTC',
// Controller-specific php settings
'controllers' => array(),
// Route-specific php settings
'routes' => array(),
),
);
}
/**
* @return array
*/
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}