1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license GPLv3, http://www.gnu.org/copyleft/gpl.html |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2019 |
6
|
|
|
* @package TYPO3 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Aimeos\Base; |
11
|
|
|
|
12
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Aimeos context class |
17
|
|
|
* |
18
|
|
|
* @package TYPO3 |
19
|
|
|
*/ |
20
|
|
|
class Context |
21
|
|
|
{ |
22
|
|
|
private static $context; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Returns the current context |
27
|
|
|
* |
28
|
|
|
* @param \Aimeos\MW\Config\Iface Configuration object |
|
|
|
|
29
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context object |
30
|
|
|
*/ |
31
|
|
|
public static function get( \Aimeos\MW\Config\Iface $config ) : \Aimeos\MShop\Context\Item\Iface |
32
|
|
|
{ |
33
|
|
|
if( self::$context === null ) |
34
|
|
|
{ |
35
|
|
|
// TYPO3 specifc context with password hasher |
36
|
|
|
$context = new \Aimeos\MShop\Context\Item\Typo3(); |
37
|
|
|
$context->setConfig( $config ); |
38
|
|
|
|
39
|
|
|
self::addDataBaseManager( $context ); |
40
|
|
|
self::addFilesystemManager( $context ); |
41
|
|
|
self::addMessageQueueManager( $context ); |
42
|
|
|
self::addLogger( $context ); |
43
|
|
|
self::addCache( $context ); |
44
|
|
|
self::addMailer( $context ); |
45
|
|
|
self::addNonce( $context ); |
46
|
|
|
self::addProcess( $context ); |
47
|
|
|
self::addSession( $context ); |
48
|
|
|
self::addHasher( $context ); |
49
|
|
|
self::addUser( $context ); |
50
|
|
|
self::addGroups( $context ); |
51
|
|
|
self::addDateTime( $context ); |
52
|
|
|
|
53
|
|
|
self::$context = $context; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Use local TS configuration from plugins |
57
|
|
|
self::$context->setConfig( $config ); |
58
|
|
|
|
59
|
|
|
return self::$context; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Adds the cache object to the context |
65
|
|
|
* |
66
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object including config |
67
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
68
|
|
|
*/ |
69
|
|
|
protected static function addCache( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
70
|
|
|
{ |
71
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_cache'] ) |
72
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_cache'] ) ) |
73
|
|
|
) { |
74
|
|
|
return $fcn( $context ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$cacheName = \Aimeos\Aimeos\Base::getExtConfig( 'cacheName', 'Typo3' ); |
78
|
|
|
if( isset( $GLOBALS['TSFE'] ) && $GLOBALS['TSFE']->headerNoCache() ) { |
79
|
|
|
$cacheName = 'None'; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
switch( $cacheName ) |
83
|
|
|
{ |
84
|
|
|
case 'None': |
85
|
|
|
$context->getConfig()->set( 'client/html/basket/cache/enable', false ); |
86
|
|
|
$cache = \Aimeos\MW\Cache\Factory::create( 'None', [], null ); |
87
|
|
|
break; |
88
|
|
|
|
89
|
|
|
case 'Typo3': |
90
|
|
|
$manager = GeneralUtility::makeInstance( \TYPO3\CMS\Core\Cache\CacheManager::class ); |
91
|
|
|
$cache = new \Aimeos\MAdmin\Cache\Proxy\Typo3( $context, $manager->getCache( 'aimeos' ) ); |
92
|
|
|
break; |
93
|
|
|
|
94
|
|
|
default: |
95
|
|
|
$cache = new \Aimeos\MAdmin\Cache\Proxy\Standard( $context ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $context->setCache( $cache ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Adds the database manager object to the context |
104
|
|
|
* |
105
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
106
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
107
|
|
|
*/ |
108
|
|
|
protected static function addDatabaseManager( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
109
|
|
|
{ |
110
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_dbm'] ) |
111
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_dbm'] ) ) |
112
|
|
|
) { |
113
|
|
|
return $fcn( $context ); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $context->setDatabaseManager( new \Aimeos\MW\DB\Manager\DBAL( $context->getConfig() ) ); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Adds the filesystem manager object to the context |
122
|
|
|
* |
123
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
124
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
125
|
|
|
*/ |
126
|
|
|
protected static function addFilesystemManager( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
127
|
|
|
{ |
128
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_fsm'] ) |
129
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_fsm'] ) ) |
130
|
|
|
) { |
131
|
|
|
return $fcn( $context ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $context->setFilesystemManager( new \Aimeos\MW\Filesystem\Manager\Standard( $context->getConfig() ) ); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Adds the password hasher object to the context |
140
|
|
|
* |
141
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
142
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
143
|
|
|
*/ |
144
|
|
|
protected static function addHasher( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
145
|
|
|
{ |
146
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_hasher'] ) |
147
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_hasher'] ) ) |
148
|
|
|
) { |
149
|
|
|
return $fcn( $context ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$factory = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Crypto\PasswordHashing\PasswordHashFactory' ); |
153
|
|
|
return $context->setPassword( new \Aimeos\MW\Password\Typo3( $factory->getDefaultHashInstance( 'FE' ) ) ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Adds the logger object to the context |
159
|
|
|
* |
160
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
161
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
162
|
|
|
*/ |
163
|
|
|
protected static function addLogger( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
164
|
|
|
{ |
165
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_logger'] ) |
166
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_logger'] ) ) |
167
|
|
|
) { |
168
|
|
|
return $fcn( $context ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
return $context->setLogger( \Aimeos\MAdmin::create( $context, 'log' ) ); |
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Adds the mailer object to the context |
177
|
|
|
* |
178
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
179
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
180
|
|
|
*/ |
181
|
|
|
protected static function addMailer( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
182
|
|
|
{ |
183
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_mailer'] ) |
184
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_mailer'] ) ) |
185
|
|
|
) { |
186
|
|
|
return $fcn( $context ); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
return $context->setMail( new \Aimeos\MW\Mail\Typo3( function() { |
190
|
|
|
return GeneralUtility::makeInstance( \TYPO3\CMS\Core\Mail\MailMessage::class ); |
191
|
|
|
} ) ); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Adds the message queue manager object to the context |
197
|
|
|
* |
198
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
199
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
200
|
|
|
*/ |
201
|
|
|
protected static function addMessageQueueManager( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
202
|
|
|
{ |
203
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_mqueue'] ) |
204
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_mqueue'] ) ) |
205
|
|
|
) { |
206
|
|
|
return $fcn( $context ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
return $context->setMessageQueueManager( new \Aimeos\MW\MQueue\Manager\Standard( $context->getConfig() ) ); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Adds the nonce value for inline JS to the context |
215
|
|
|
* |
216
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
217
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
218
|
|
|
*/ |
219
|
|
|
protected static function addNonce( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
220
|
|
|
{ |
221
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_nounce'] ) |
222
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_nounce'] ) ) |
223
|
|
|
) { |
224
|
|
|
return $fcn( $context ); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
return $context->setNonce( base64_encode( random_bytes( 16 ) ) ); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Adds the process object to the context |
233
|
|
|
* |
234
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
235
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
236
|
|
|
*/ |
237
|
|
|
protected static function addProcess( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
238
|
|
|
{ |
239
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_process'] ) |
240
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_process'] ) ) |
241
|
|
|
) { |
242
|
|
|
return $fcn( $context ); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
$process = new \Aimeos\MW\Process\Pcntl( \Aimeos\Aimeos\Base::getExtConfig( 'pcntlMax', 4 ) ); |
246
|
|
|
|
247
|
|
|
// Reset before child processes are spawned to avoid lost DB connections afterwards |
248
|
|
|
if( method_exists( '\TYPO3\CMS\Core\Database\ConnectionPool', 'resetConnections' ) === false |
249
|
|
|
|| $process->isAvailable() === false |
250
|
|
|
) { |
251
|
|
|
$process = new \Aimeos\MW\Process\None(); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
return $context->setProcess( $process ); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Adds the session object to the context |
260
|
|
|
* |
261
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
262
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
263
|
|
|
*/ |
264
|
|
|
protected static function addSession( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
265
|
|
|
{ |
266
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_session'] ) |
267
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_session'] ) ) |
268
|
|
|
) { |
269
|
|
|
return $fcn( $context ); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
$class = \TYPO3\CMS\Core\Authentication\CommandLineUserAuthentication::class; |
273
|
|
|
|
274
|
|
|
if( isset( $GLOBALS['TSFE']->fe_user ) ) { |
275
|
|
|
$session = new \Aimeos\MW\Session\Typo3( $GLOBALS['TSFE']->fe_user ); |
276
|
|
|
} elseif( isset( $GLOBALS['BE_USER'] ) && !( $GLOBALS['BE_USER'] instanceof $class ) ) { |
277
|
|
|
$session = new \Aimeos\MW\Session\Typo3( $GLOBALS['BE_USER'] ); |
278
|
|
|
} else { |
279
|
|
|
$session = new \Aimeos\MW\Session\None(); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
return $context->setSession( $session ); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Adds the user ID and editor name to the context |
288
|
|
|
* |
289
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
290
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
291
|
|
|
*/ |
292
|
|
|
protected static function addUser( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
293
|
|
|
{ |
294
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_user'] ) |
295
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_user'] ) ) |
296
|
|
|
) { |
297
|
|
|
return $fcn( $context ); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
$t3context = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Context\Context' ); |
301
|
|
|
|
302
|
|
|
if( TYPO3_MODE === 'FE' && $t3context->getPropertyFromAspect( 'frontend.user', 'isLoggedIn' ) ) |
303
|
|
|
{ |
304
|
|
|
$context->setUserId( $GLOBALS['TSFE']->fe_user->user[$GLOBALS['TSFE']->fe_user->userid_column] ); |
305
|
|
|
$context->setEditor( (string) $GLOBALS['TSFE']->fe_user->user['username'] ); |
306
|
|
|
} |
307
|
|
|
elseif( TYPO3_MODE === 'BE' && isset( $GLOBALS['BE_USER']->user['username'] ) ) |
308
|
|
|
{ |
309
|
|
|
$context->setEditor( (string) $GLOBALS['BE_USER']->user['username'] ); |
310
|
|
|
} |
311
|
|
|
else |
312
|
|
|
{ |
313
|
|
|
$context->setEditor( (string) GeneralUtility::getIndpEnv( 'REMOTE_ADDR' ) ); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
return $context; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Adds the group IDs to the context |
322
|
|
|
* |
323
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
324
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
325
|
|
|
*/ |
326
|
|
|
protected static function addGroups( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
327
|
|
|
{ |
328
|
|
|
if( isset( $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_groups'] ) |
329
|
|
|
&& is_callable( ( $fcn = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['aimeos']['aimeos_context_groups'] ) ) |
330
|
|
|
) { |
331
|
|
|
return $fcn( $context ); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
$t3context = GeneralUtility::makeInstance( 'TYPO3\CMS\Core\Context\Context' ); |
335
|
|
|
|
336
|
|
|
if( TYPO3_MODE === 'FE' && $t3context->getPropertyFromAspect( 'frontend.user', 'isLoggedIn' ) ) |
337
|
|
|
{ |
338
|
|
|
$ids = GeneralUtility::trimExplode( ',', $GLOBALS['TSFE']->fe_user->user['usergroup'] ); |
339
|
|
|
$context->setGroupIds( $ids ); |
340
|
|
|
} |
341
|
|
|
elseif( TYPO3_MODE === 'BE' && $GLOBALS['BE_USER']->userGroups ) |
342
|
|
|
{ |
343
|
|
|
$ids = array_keys( $GLOBALS['BE_USER']->userGroups ); |
344
|
|
|
$context->setGroupIds( $ids ); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
return $context; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* Adds the frontend date time to the context |
353
|
|
|
* |
354
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object including config |
355
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Modified context object |
356
|
|
|
*/ |
357
|
|
|
protected static function addDateTime( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Context\Item\Iface |
358
|
|
|
{ |
359
|
|
|
if( TYPO3_MODE === 'FE' && isset( $GLOBALS['BE_USER']->adminPanel ) |
360
|
|
|
&& class_exists( 'TYPO3\\CMS\\Adminpanel\\Service\\ConfigurationService' ) ) |
361
|
|
|
{ |
362
|
|
|
$service = GeneralUtility::makeInstance( 'TYPO3\\CMS\\Adminpanel\\Service\\ConfigurationService' ); |
363
|
|
|
$tstamp = strtotime( $service->getConfigurationOption( 'preview', 'simulateDate' ) ); |
364
|
|
|
|
365
|
|
|
if( !empty( $tstamp ) ) { |
366
|
|
|
$context->setDateTime( date( 'Y-m-d H:i:s', $tstamp ) ); |
367
|
|
|
} |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
return $context; |
371
|
|
|
} |
372
|
|
|
} |
373
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths