1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://www.gnu.org/copyleft/lgpl.html |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
6
|
|
|
* @package flow |
7
|
|
|
* @subpackage Base |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Shop\Base; |
12
|
|
|
|
13
|
|
|
use Neos\Flow\Annotations as Flow; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class providing the context object |
18
|
|
|
* |
19
|
|
|
* @package flow |
20
|
|
|
* @subpackage Base |
21
|
|
|
* @Flow\Scope("singleton") |
22
|
|
|
*/ |
23
|
|
|
class Context |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var \Aimeos\MShop\Context\Item\Iface |
27
|
|
|
*/ |
28
|
|
|
private static $context; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private $settings; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \Neos\Cache\Frontend\StringFrontend |
37
|
|
|
*/ |
38
|
|
|
private $cache; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var \Aimeos\Shop\Base\Aimeos |
42
|
|
|
* @Flow\Inject |
43
|
|
|
*/ |
44
|
|
|
protected $aimeos; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var \Aimeos\Shop\Base\Config |
48
|
|
|
* @Flow\Inject |
49
|
|
|
*/ |
50
|
|
|
protected $config; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var \Aimeos\Shop\Base\I18n |
54
|
|
|
* @Flow\Inject |
55
|
|
|
*/ |
56
|
|
|
protected $i18n; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var \Aimeos\Shop\Base\Locale |
60
|
|
|
* @Flow\Inject |
61
|
|
|
*/ |
62
|
|
|
protected $locale; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var \Neos\SwiftMailer\MailerInterface |
66
|
|
|
* @Flow\Inject |
67
|
|
|
*/ |
68
|
|
|
protected $mailer; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var \Neos\Flow\Session\SessionInterface |
72
|
|
|
* @Flow\Inject(lazy = FALSE) |
73
|
|
|
*/ |
74
|
|
|
protected $session; |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns the current context. |
79
|
|
|
* |
80
|
|
|
* @param \Neos\Flow\Mvc\RequestInterface|null $request Request object |
81
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface |
82
|
|
|
*/ |
83
|
|
|
public function get( \Neos\Flow\Mvc\RequestInterface $request = null, $type = 'frontend' ) |
84
|
|
|
{ |
85
|
|
|
$config = $this->config->get( $type ); |
86
|
|
|
|
87
|
|
|
if( self::$context === null ) |
88
|
|
|
{ |
89
|
|
|
$context = new \Aimeos\MShop\Context\Item\Standard(); |
90
|
|
|
$context->setConfig( $config ); |
91
|
|
|
|
92
|
|
|
$this->addDataBaseManager( $context ); |
93
|
|
|
$this->addFilesystemManager( $context ); |
94
|
|
|
$this->addMessageQueueManager( $context ); |
95
|
|
|
$this->addCache( $context ); |
96
|
|
|
$this->addLogger( $context ); |
97
|
|
|
$this->addMailer( $context ); |
98
|
|
|
$this->addProcess( $context ); |
99
|
|
|
|
100
|
|
|
self::$context = $context; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$context = self::$context; |
104
|
|
|
$context->setConfig( $config ); |
105
|
|
|
|
106
|
|
|
if( $request !== null ) |
107
|
|
|
{ |
108
|
|
|
$localeItem = $this->locale->get( $context, $request ); |
109
|
|
|
$context->setI18n( $this->i18n->get( array( $localeItem->getLanguageId() ) ) ); |
110
|
|
|
$context->setLocale( $localeItem ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$this->addSession( $context ); |
114
|
|
|
$this->addUser( $context, $request ); |
115
|
|
|
|
116
|
|
|
return $context; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Adds the cache object to the context |
122
|
|
|
* |
123
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object including config |
124
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
125
|
|
|
*/ |
126
|
|
|
protected function addCache( \Aimeos\MShop\Context\Item\Iface $context ) |
127
|
|
|
{ |
128
|
|
|
$config = $context->getConfig(); |
129
|
|
|
|
130
|
|
|
switch( $config->get( 'flow/cache/name', 'Flow' ) ) |
131
|
|
|
{ |
132
|
|
|
case 'None': |
133
|
|
|
$config->set( 'client/html/basket/cache/enable', false ); |
134
|
|
|
return $context->setCache( \Aimeos\MW\Cache\Factory::createManager( 'None', array(), null ) ); |
135
|
|
|
|
136
|
|
|
case 'Flow': |
137
|
|
|
return $context->setCache( new \Aimeos\MAdmin\Cache\Proxy\Flow( $context, $this->cache ) ); |
138
|
|
|
|
139
|
|
|
default: |
140
|
|
|
return $context->setCache( new \Aimeos\MAdmin\Cache\Proxy\Standard( $context ) ); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Adds the database manager object to the context |
147
|
|
|
* |
148
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
149
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
150
|
|
|
*/ |
151
|
|
|
protected function addDatabaseManager( \Aimeos\MShop\Context\Item\Iface $context ) |
152
|
|
|
{ |
153
|
|
|
$dbm = new \Aimeos\MW\DB\Manager\DBAL( $context->getConfig() ); |
154
|
|
|
|
155
|
|
|
return $context->setDatabaseManager( $dbm ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Adds the filesystem manager object to the context |
161
|
|
|
* |
162
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
163
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
164
|
|
|
*/ |
165
|
|
|
protected function addFilesystemManager( \Aimeos\MShop\Context\Item\Iface $context ) |
166
|
|
|
{ |
167
|
|
|
$fs = new \Aimeos\MW\Filesystem\Manager\Standard( $context->getConfig() ); |
168
|
|
|
|
169
|
|
|
return $context->setFilesystemManager( $fs ); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Adds the logger object to the context |
175
|
|
|
* |
176
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
177
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
178
|
|
|
*/ |
179
|
|
|
protected function addLogger( \Aimeos\MShop\Context\Item\Iface $context ) |
180
|
|
|
{ |
181
|
|
|
$logger = \Aimeos\MAdmin\Log\Manager\Factory::createManager( $context ); |
182
|
|
|
|
183
|
|
|
return $context->setLogger( $logger ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Adds the mailer object to the context |
190
|
|
|
* |
191
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
192
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
193
|
|
|
*/ |
194
|
|
|
protected function addMailer( \Aimeos\MShop\Context\Item\Iface $context ) |
195
|
|
|
{ |
196
|
|
|
$mail = new \Aimeos\MW\Mail\Swift( $this->mailer ); |
197
|
|
|
|
198
|
|
|
return $context->setMail( $mail ); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Adds the message queue manager object to the context |
204
|
|
|
* |
205
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
206
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
207
|
|
|
*/ |
208
|
|
|
protected function addMessageQueueManager( \Aimeos\MShop\Context\Item\Iface $context ) |
209
|
|
|
{ |
210
|
|
|
$mq = new \Aimeos\MW\MQueue\Manager\Standard( $context->getConfig() ); |
211
|
|
|
|
212
|
|
|
return $context->setMessageQueueManager( $mq ); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Adds the process object to the context |
218
|
|
|
* |
219
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
220
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
221
|
|
|
*/ |
222
|
|
|
protected function addProcess( \Aimeos\MShop\Context\Item\Iface $context ) |
223
|
|
|
{ |
224
|
|
|
$config = $context->getConfig(); |
225
|
|
|
$max = $config->get( 'pcntl_max', 4 ); |
226
|
|
|
$prio = $config->get( 'pcntl_priority', 19 ); |
227
|
|
|
|
228
|
|
|
$process = new \Aimeos\MW\Process\Pcntl( $max, $prio ); |
229
|
|
|
$process = new \Aimeos\MW\Process\Decorator\Check( $process ); |
230
|
|
|
|
231
|
|
|
return $context->setProcess( $process ); |
|
|
|
|
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Adds the session object to the context |
237
|
|
|
* |
238
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
239
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
240
|
|
|
*/ |
241
|
|
|
protected function addSession( \Aimeos\MShop\Context\Item\Iface $context ) |
242
|
|
|
{ |
243
|
|
|
$session = new \Aimeos\MW\Session\Flow( $this->session ); |
244
|
|
|
|
245
|
|
|
return $context->setSession( $session ); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Adds the user ID and name if available |
251
|
|
|
* |
252
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
253
|
|
|
* @param \Neos\Flow\Mvc\RequestInterface|null $request Request object |
254
|
|
|
*/ |
255
|
|
|
protected function addUser( \Aimeos\MShop\Context\Item\Iface $context, \Neos\Flow\Mvc\RequestInterface $request = null ) |
256
|
|
|
{ |
257
|
|
|
if( $request instanceof \Neos\Flow\Mvc\ActionRequest ) { |
258
|
|
|
$context->setEditor( $request->getHttpRequest()->getClientIpAddress() ); |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Inject the settings |
265
|
|
|
* |
266
|
|
|
* @param array $settings |
267
|
|
|
* @return void |
268
|
|
|
*/ |
269
|
|
|
public function injectSettings( array $settings ) |
270
|
|
|
{ |
271
|
|
|
$this->settings = $settings; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Sets the Aimeos shop cache |
277
|
|
|
* |
278
|
|
|
* @param \Neos\Cache\Frontend\StringFrontend $cache Cache for shop data |
279
|
|
|
* @return void |
280
|
|
|
*/ |
281
|
|
|
public function setCache( \Neos\Cache\Frontend\StringFrontend $cache ) |
282
|
|
|
{ |
283
|
|
|
$this->cache = $cache; |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.