|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* Core Module Bootstrap |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
* @author Carsten Bleek <[email protected]> |
|
9
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
10
|
|
|
* @author Miroslav Fedeleš <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** Core */ |
|
14
|
|
|
namespace Core; |
|
15
|
|
|
|
|
16
|
|
|
use Core\Listener\AjaxRouteListener; |
|
17
|
|
|
use Zend\Mvc\MvcEvent; |
|
18
|
|
|
use Core\Listener\LanguageRouteListener; |
|
19
|
|
|
use Core\Listener\AjaxRenderListener; |
|
20
|
|
|
use Core\Listener\XmlRenderListener; |
|
21
|
|
|
use Core\Listener\EnforceJsonResponseListener; |
|
22
|
|
|
use Core\Listener\StringListener; |
|
23
|
|
|
use Core\Listener\TracyListener; |
|
24
|
|
|
use Core\Service\Tracy as TracyService; |
|
25
|
|
|
use Zend\ModuleManager\Feature\ConsoleBannerProviderInterface; |
|
26
|
|
|
use Zend\Console\Adapter\AdapterInterface as Console; |
|
27
|
|
|
use Core\Listener\ErrorHandlerListener; |
|
28
|
|
|
use Core\Repository\DoctrineMongoODM\PersistenceListener; |
|
29
|
|
|
use Core\Listener\NotificationAjaxHandler; |
|
30
|
|
|
use Core\Listener\Events\NotificationEvent; |
|
31
|
|
|
use Doctrine\ODM\MongoDB\Types\Type as DoctrineType; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Bootstrap class of the Core module |
|
35
|
|
|
* |
|
36
|
|
|
*/ |
|
37
|
|
|
class Module implements ConsoleBannerProviderInterface |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
public function getConsoleBanner(Console $console) |
|
41
|
|
|
{ |
|
42
|
|
|
$version = `git describe 2>/dev/null`; |
|
43
|
|
|
$name = 'YAWIK ' . trim($version); |
|
44
|
|
|
$width = $console->getWidth(); |
|
45
|
|
|
return sprintf( |
|
46
|
|
|
"==%1\$s==\n%2\$s%3\$s\n**%1\$s**\n", |
|
47
|
|
|
str_repeat('-', $width - 4), |
|
48
|
|
|
str_repeat(' ', floor(($width - strlen($name)) / 2)), |
|
49
|
|
|
$name |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Sets up services on the bootstrap event. |
|
55
|
|
|
* |
|
56
|
|
|
* @internal |
|
57
|
|
|
* Creates the translation service and a ModuleRouteListener |
|
58
|
|
|
* |
|
59
|
|
|
* @param MvcEvent $e |
|
60
|
|
|
*/ |
|
61
|
|
|
public function onBootstrap(MvcEvent $e) |
|
62
|
|
|
{ |
|
63
|
|
|
// Register the TimezoneAwareDate type with DoctrineMongoODM |
|
64
|
|
|
// Use it in Annotations ( @Field(type="tz_date") ) |
|
65
|
|
|
if (!DoctrineType::hasType('tz_date')) { |
|
66
|
|
|
DoctrineType::addType( |
|
67
|
|
|
'tz_date', |
|
68
|
|
|
'\Core\Repository\DoctrineMongoODM\Types\TimezoneAwareDate' |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$sm = $e->getApplication()->getServiceManager(); |
|
73
|
|
|
$translator = $sm->get('translator'); // initialise translator! |
|
74
|
|
|
\Zend\Validator\AbstractValidator::setDefaultTranslator($translator); |
|
|
|
|
|
|
75
|
|
|
$eventManager = $e->getApplication()->getEventManager(); |
|
76
|
|
|
$sharedManager = $eventManager->getSharedManager(); |
|
77
|
|
|
|
|
78
|
|
|
$tracyConfig = $sm->get('Config')['tracy']; |
|
79
|
|
|
|
|
80
|
|
|
if ($tracyConfig['enabled']) { |
|
81
|
|
|
(new TracyService())->register($tracyConfig); |
|
82
|
|
|
(new TracyListener())->attach($eventManager); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (!\Zend\Console\Console::isConsole()) { |
|
86
|
|
|
$redirectCallback = function () use ($e) { |
|
87
|
|
|
$routeMatch = $e->getRouteMatch(); |
|
88
|
|
|
$lang = $routeMatch ? $routeMatch->getParam('lang', 'en') : 'en'; |
|
89
|
|
|
$uri = $e->getRouter()->getBaseUrl() . '/' . $lang . '/error'; |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
header('Location: ' . $uri); |
|
92
|
|
|
}; |
|
93
|
|
|
|
|
94
|
|
|
if (!$tracyConfig['enabled']) { |
|
95
|
|
|
$errorHandlerListener = new ErrorHandlerListener($sm->get('ErrorLogger'), $redirectCallback); |
|
|
|
|
|
|
96
|
|
|
$errorHandlerListener->attach($eventManager); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/* @var \Core\Options\ModuleOptions $options */ |
|
100
|
|
|
$languageRouteListener = new LanguageRouteListener($sm->get('Core/Locale')); |
|
|
|
|
|
|
101
|
|
|
$languageRouteListener->attach($eventManager); |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
$ajaxRenderListener = new AjaxRenderListener(); |
|
105
|
|
|
$ajaxRenderListener->attach($eventManager); |
|
106
|
|
|
|
|
107
|
|
|
$ajaxRouteListener = $sm->get(AjaxRouteListener::class); |
|
108
|
|
|
$ajaxRouteListener->attach($eventManager); |
|
109
|
|
|
|
|
110
|
|
|
$xmlRenderListener = new XmlRenderListener(); |
|
111
|
|
|
$xmlRenderListener->attach($eventManager); |
|
112
|
|
|
|
|
113
|
|
|
$enforceJsonResponseListener = new EnforceJsonResponseListener(); |
|
114
|
|
|
$enforceJsonResponseListener->attach($eventManager); |
|
115
|
|
|
|
|
116
|
|
|
$stringListener = new StringListener(); |
|
117
|
|
|
$stringListener->attach($eventManager); |
|
118
|
|
|
|
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
$notificationListener = $sm->get('Core/Listener/Notification'); |
|
122
|
|
|
$notificationListener->attachShared($sharedManager); |
|
123
|
|
|
$notificationAjaxHandler = new NotificationAjaxHandler(); |
|
124
|
|
|
$eventManager->attach(MvcEvent::EVENT_DISPATCH, array($notificationAjaxHandler, 'injectView'), -20); |
|
125
|
|
|
$notificationListener->attach(NotificationEvent::EVENT_NOTIFICATION_HTML, array($notificationAjaxHandler, 'render'), -20); |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
$eventManager->attach( |
|
129
|
|
|
MvcEvent::EVENT_DISPATCH_ERROR, |
|
130
|
|
|
function ($event) { |
|
131
|
|
|
$application = $event->getApplication(); |
|
132
|
|
|
if ($application::ERROR_EXCEPTION == $event->getError()) { |
|
133
|
|
|
$ex = $event->getParam('exception'); |
|
134
|
|
|
if (404 == $ex->getCode()) { |
|
135
|
|
|
$event->setError($application::ERROR_CONTROLLER_NOT_FOUND); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
}, |
|
140
|
|
|
500 |
|
141
|
|
|
); |
|
142
|
|
|
$eventManager->attach( |
|
143
|
|
|
MvcEvent::EVENT_DISPATCH, |
|
144
|
|
|
function ($event) use ($eventManager) { |
|
145
|
|
|
$eventManager->trigger('postDispatch', $event); |
|
146
|
|
|
}, |
|
147
|
|
|
-150 |
|
148
|
|
|
); |
|
149
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Loads module specific configuration. |
|
154
|
|
|
* |
|
155
|
|
|
* @return array |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getConfig() |
|
158
|
|
|
{ |
|
159
|
|
|
$config = include __DIR__ . '/config/module.config.php'; |
|
160
|
|
|
return $config; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Loads module specific autoloader configuration. |
|
165
|
|
|
* |
|
166
|
|
|
* @return array |
|
167
|
|
|
*/ |
|
168
|
|
View Code Duplication |
public function getAutoloaderConfig() |
|
|
|
|
|
|
169
|
|
|
{ |
|
170
|
|
|
return array( |
|
171
|
|
|
'Zend\Loader\ClassMapAutoloader' => [ |
|
172
|
|
|
__DIR__ . '/src/autoload_classmap.php' |
|
173
|
|
|
], |
|
174
|
|
|
'Zend\Loader\StandardAutoloader' => array( |
|
175
|
|
|
'namespaces' => array( |
|
176
|
|
|
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, |
|
177
|
|
|
'CoreTest' => __DIR__ . '/test/' . 'CoreTest', |
|
178
|
|
|
'CoreTestUtils' => __DIR__ . '/test/CoreTestUtils', |
|
179
|
|
|
), |
|
180
|
|
|
), |
|
181
|
|
|
); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: