1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2024 |
6
|
|
|
* @package MShop |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Common objects which must to be available for all manager objects. |
15
|
|
|
* |
16
|
|
|
* @package MShop |
17
|
|
|
*/ |
18
|
|
|
class Context implements \Aimeos\MShop\ContextIface |
19
|
|
|
{ |
20
|
|
|
private ?\Aimeos\Base\Cache\Iface $cache = null; |
21
|
|
|
private ?\Aimeos\Base\Config\Iface $config = null; |
22
|
|
|
private ?\Aimeos\Base\DB\Manager\Iface $db = null; |
23
|
|
|
private ?\Aimeos\Base\Filesystem\Manager\Iface $fs = null; |
24
|
|
|
private ?\Aimeos\MShop\Locale\Item\Iface $locale = null; |
25
|
|
|
private ?\Aimeos\Base\Logger\Iface $logger = null; |
26
|
|
|
private ?\Aimeos\Base\Mail\Iface $mail = null; |
27
|
|
|
private ?\Aimeos\Base\MQueue\Manager\Iface $queue = null; |
28
|
|
|
private ?\Aimeos\Base\Password\Iface $password = null; |
29
|
|
|
private ?\Aimeos\Base\Process\Iface $process = null; |
30
|
|
|
private ?\Aimeos\Base\Session\Iface $session = null; |
31
|
|
|
private ?\Aimeos\Base\View\Iface $view = null; |
32
|
|
|
private ?string $datetime = null; |
33
|
|
|
private ?string $nonce = null; |
34
|
|
|
private ?string $token = null; |
35
|
|
|
private string $editor = ''; |
36
|
|
|
private array $i18n = []; |
37
|
|
|
private $groups = null; |
38
|
|
|
private $user = null; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Cleans up the stored resources |
43
|
|
|
*/ |
44
|
|
|
public function __destruct() |
45
|
|
|
{ |
46
|
|
|
$this->cache = null; |
47
|
|
|
$this->config = null; |
48
|
|
|
$this->db = null; |
49
|
|
|
$this->fs = null; |
50
|
|
|
$this->locale = null; |
51
|
|
|
$this->logger = null; |
52
|
|
|
$this->mail = null; |
53
|
|
|
$this->queue = null; |
54
|
|
|
$this->password = null; |
55
|
|
|
$this->process = null; |
56
|
|
|
$this->session = null; |
57
|
|
|
$this->view = null; |
58
|
|
|
$this->i18n = []; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Clones internal objects of the context item. |
64
|
|
|
*/ |
65
|
|
|
public function __clone() |
66
|
|
|
{ |
67
|
|
|
$this->cache = ( isset( $this->cache ) ? clone $this->cache : null ); |
68
|
|
|
$this->config = ( isset( $this->config ) ? clone $this->config : null ); |
69
|
|
|
$this->fs = ( isset( $this->fs ) ? clone $this->fs : null ); |
70
|
|
|
$this->locale = ( isset( $this->locale ) ? clone $this->locale : null ); |
71
|
|
|
$this->logger = ( isset( $this->logger ) ? clone $this->logger : null ); |
72
|
|
|
$this->mail = ( isset( $this->mail ) ? clone $this->mail : null ); |
73
|
|
|
$this->queue = ( isset( $this->queue ) ? clone $this->queue : null ); |
74
|
|
|
$this->password = ( isset( $this->password ) ? clone $this->password : null ); |
75
|
|
|
$this->process = ( isset( $this->process ) ? clone $this->process : null ); |
76
|
|
|
$this->session = ( isset( $this->session ) ? clone $this->session : null ); |
77
|
|
|
// view is always cloned |
78
|
|
|
|
79
|
|
|
foreach( $this->i18n as $locale => $object ) { |
80
|
|
|
$this->i18n[$locale] = clone $this->i18n[$locale]; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Cleans up internal objects of the context item |
87
|
|
|
*/ |
88
|
|
|
public function __sleep() : array |
89
|
|
|
{ |
90
|
|
|
$objects = array( |
91
|
|
|
$this->cache, $this->config, $this->db, $this->fs, $this->locale, $this->logger, |
92
|
|
|
$this->mail, $this->queue, $this->password, $this->process, $this->session, $this->view |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
foreach( $objects as $object ) |
96
|
|
|
{ |
97
|
|
|
if( is_object( $object ) && method_exists( $object, '__sleep' ) ) { |
98
|
|
|
$object->__sleep(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return get_object_vars( $this ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Returns a hash identifying the context object. |
108
|
|
|
* |
109
|
|
|
* @return string Hash for identifying the context object |
110
|
|
|
*/ |
111
|
|
|
public function __toString() : string |
112
|
|
|
{ |
113
|
|
|
$objects = array( |
114
|
|
|
$this, $this->cache, $this->config, $this->db, $this->fs, $this->locale, |
115
|
|
|
$this->logger, $this->mail, $this->queue, $this->password, $this->process, |
116
|
|
|
$this->session, $this->view |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
return md5( $this->hash( $objects ) ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Sets the cache object. |
125
|
|
|
* |
126
|
|
|
* @param \Aimeos\Base\Cache\Iface $cache Cache object |
127
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
128
|
|
|
*/ |
129
|
|
|
public function setCache( \Aimeos\Base\Cache\Iface $cache ) : \Aimeos\MShop\ContextIface |
130
|
|
|
{ |
131
|
|
|
$this->cache = $cache; |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns the cache object. |
139
|
|
|
* |
140
|
|
|
* @return \Aimeos\Base\Cache\Iface Cache object |
141
|
|
|
*/ |
142
|
|
|
public function cache() : \Aimeos\Base\Cache\Iface |
143
|
|
|
{ |
144
|
|
|
if( !isset( $this->cache ) ) { |
145
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Cache object not available' ) ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
return $this->cache; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Sets the configuration object. |
154
|
|
|
* |
155
|
|
|
* @param \Aimeos\Base\Config\Iface $config Configuration object |
156
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
157
|
|
|
*/ |
158
|
|
|
public function setConfig( \Aimeos\Base\Config\Iface $config ) : \Aimeos\MShop\ContextIface |
159
|
|
|
{ |
160
|
|
|
$this->config = $config; |
161
|
|
|
|
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Returns the configuration object. |
168
|
|
|
* |
169
|
|
|
* @return \Aimeos\Base\Config\Iface Configuration object |
170
|
|
|
*/ |
171
|
|
|
public function config() : \Aimeos\Base\Config\Iface |
172
|
|
|
{ |
173
|
|
|
if( !isset( $this->config ) ) { |
174
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Configuration object not available' ) ); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
return $this->config; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Sets the database connection manager object. |
183
|
|
|
* |
184
|
|
|
* @param \Aimeos\Base\DB\Manager\Iface $manager Database manager object |
185
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
186
|
|
|
*/ |
187
|
|
|
public function setDatabaseManager( \Aimeos\Base\DB\Manager\Iface $manager ) : \Aimeos\MShop\ContextIface |
188
|
|
|
{ |
189
|
|
|
$this->db = $manager; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Returns the database connection object. |
197
|
|
|
* |
198
|
|
|
* @param string $resource Database resource name |
199
|
|
|
* @param bool $new Create a new database connection |
200
|
|
|
* @return \Aimeos\Base\DB\Manager\Iface Database manager object |
201
|
|
|
*/ |
202
|
|
|
public function db( string $resource = 'db', bool $new = false ) : \Aimeos\Base\DB\Connection\Iface |
203
|
|
|
{ |
204
|
|
|
if( !isset( $this->db ) ) { |
205
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Database manager object not available' ) ); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
return $this->db->get( $resource, $new ); |
|
|
|
|
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Sets the current date and time |
214
|
|
|
* |
215
|
|
|
* @param string $datetime Date and time as ISO string (YYYY-MM-DD HH:mm:ss) |
216
|
|
|
*/ |
217
|
|
|
public function setDateTime( string $datetime ) : \Aimeos\MShop\ContextIface |
218
|
|
|
{ |
219
|
|
|
$regex = '/^[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/'; |
220
|
|
|
|
221
|
|
|
if( preg_match( $regex, (string) $datetime ) !== 1 ) { |
222
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Invalid characters in date "%1$s". ISO format "YYYY-MM-DD hh:mm:ss" expected.', $datetime ) ); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$this->datetime = $datetime; |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Returns the current date and time |
233
|
|
|
* This is especially useful to share the same request time or if applications |
234
|
|
|
* allow to travel in time. |
235
|
|
|
* |
236
|
|
|
* @return string Current date and time as ISO string (YYYY-MM-DD HH:mm:ss) |
237
|
|
|
*/ |
238
|
|
|
public function datetime() : string |
239
|
|
|
{ |
240
|
|
|
if( $this->datetime === null ) { |
241
|
|
|
$this->datetime = date( 'Y-m-d H:i:00' ); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
return $this->datetime; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Sets the file system manager object. |
250
|
|
|
* |
251
|
|
|
* @param \Aimeos\Base\Filesystem\Manager\Iface $manager File system object |
252
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
253
|
|
|
*/ |
254
|
|
|
public function setFilesystemManager( \Aimeos\Base\Filesystem\Manager\Iface $manager ) : \Aimeos\MShop\ContextIface |
255
|
|
|
{ |
256
|
|
|
$this->fs = $manager; |
257
|
|
|
return $this; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Returns the file system object for the given resource name. |
263
|
|
|
* |
264
|
|
|
* @param string $resource Resource name, e.g. "fs-admin" |
265
|
|
|
* @return \Aimeos\Base\Filesystem\Iface File system object |
266
|
|
|
*/ |
267
|
|
|
public function fs( string $resource = 'fs' ) : \Aimeos\Base\Filesystem\Iface |
268
|
|
|
{ |
269
|
|
|
if( !isset( $this->fs ) ) { |
270
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'File system manager object not available' ) ); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
return $this->fs->get( $resource ); |
|
|
|
|
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Sets the translation/internationalization objects. |
279
|
|
|
* |
280
|
|
|
* @param array $translations Associative list of internationalization objects implementing |
281
|
|
|
* \Aimeos\Base\Translation\Iface with locale as key |
282
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
283
|
|
|
*/ |
284
|
|
|
public function setI18n( array $translations ) : \Aimeos\MShop\ContextIface |
285
|
|
|
{ |
286
|
|
|
$this->i18n = $translations; |
287
|
|
|
|
288
|
|
|
return $this; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Returns the translation/internationalization object for the given locale (null for default one). |
294
|
|
|
* |
295
|
|
|
* @param string|null $locale Two letter language ISO code for specific language instead of default one |
296
|
|
|
* @return \Aimeos\Base\Translation\Iface Internationalization object |
297
|
|
|
*/ |
298
|
|
|
public function i18n( string $locale = null ) : \Aimeos\Base\Translation\Iface |
299
|
|
|
{ |
300
|
|
|
if( isset( $this->locale ) && $locale === null ) { |
301
|
|
|
$locale = $this->locale()->getLanguageId(); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
if( isset( $this->locale ) && $locale === null && reset( $this->i18n ) !== false ) { |
305
|
|
|
$locale = key( $this->i18n ); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
if( isset( $this->i18n[$locale] ) ) { |
309
|
|
|
return $this->i18n[$locale]; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
if( isset( $this->i18n['en'] ) ) { |
313
|
|
|
return $this->i18n['en']; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/// Locale ID %1$s |
317
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Internationalization object not available for "%1$s"', $locale ) ); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Translates a string if possible |
323
|
|
|
* |
324
|
|
|
* @param string $name Name of the translation domain |
325
|
|
|
* @param string $singular Singular string to translate |
326
|
|
|
* @param string $plural Plural string to translate if count is not one |
327
|
|
|
* @param int $number Number for plural translations |
328
|
|
|
* @param string|null $locale Locale (e.g. en, en_US, de, etc.) or NULL for current locale |
329
|
|
|
* @return string Translated string if possible |
330
|
|
|
*/ |
331
|
|
|
public function translate( string $domain, string $singular, string $plural = null, int $number = 1, string $locale = null ) : string |
332
|
|
|
{ |
333
|
|
|
if( empty( $this->i18n ) ) { |
334
|
|
|
return $number === 1 ? $singular : $plural; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
if( $plural ) { |
338
|
|
|
return $this->i18n( $locale )->dn( $domain, $singular, $plural, $number ); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
return $this->i18n( $locale )->dt( $domain, $singular ); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Sets the localization object. |
347
|
|
|
* |
348
|
|
|
* @param \Aimeos\MShop\Locale\Item\Iface $locale Localization object |
349
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
350
|
|
|
*/ |
351
|
|
|
public function setLocale( \Aimeos\MShop\Locale\Item\Iface $locale ) : \Aimeos\MShop\ContextIface |
352
|
|
|
{ |
353
|
|
|
$this->locale = $locale; |
354
|
|
|
|
355
|
|
|
return $this; |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* Returns the localization object. |
361
|
|
|
* |
362
|
|
|
* @return \Aimeos\MShop\Locale\Item\Iface Localization object |
363
|
|
|
*/ |
364
|
|
|
public function locale() : \Aimeos\MShop\Locale\Item\Iface |
365
|
|
|
{ |
366
|
|
|
if( !isset( $this->locale ) ) { |
367
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Locale object not available' ) ); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
return $this->locale; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Sets the logger object. |
376
|
|
|
* |
377
|
|
|
* @param \Aimeos\Base\Logger\Iface $logger Logger object |
378
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
379
|
|
|
*/ |
380
|
|
|
public function setLogger( \Aimeos\Base\Logger\Iface $logger ) : \Aimeos\MShop\ContextIface |
381
|
|
|
{ |
382
|
|
|
$this->logger = $logger; |
383
|
|
|
|
384
|
|
|
return $this; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Returns the logger object. |
390
|
|
|
* |
391
|
|
|
* @return \Aimeos\Base\Logger\Iface Logger object |
392
|
|
|
*/ |
393
|
|
|
public function logger() : \Aimeos\Base\Logger\Iface |
394
|
|
|
{ |
395
|
|
|
if( !isset( $this->logger ) ) { |
396
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Log manager object not available' ) ); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
return $this->logger; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* Sets the mail object. |
405
|
|
|
* |
406
|
|
|
* @param \Aimeos\Base\Mail\Iface $mail Mail object |
407
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
408
|
|
|
*/ |
409
|
|
|
public function setMail( \Aimeos\Base\Mail\Iface $mail ) : \Aimeos\MShop\ContextIface |
410
|
|
|
{ |
411
|
|
|
$this->mail = $mail; |
412
|
|
|
|
413
|
|
|
return $this; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Returns the mail object. |
419
|
|
|
* |
420
|
|
|
* @return \Aimeos\Base\Mail\Iface Mail object |
421
|
|
|
*/ |
422
|
|
|
public function mail() : \Aimeos\Base\Mail\Iface |
423
|
|
|
{ |
424
|
|
|
if( !isset( $this->mail ) ) { |
425
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Mail object not available' ) ); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
return $this->mail; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Sets the message queue manager object. |
434
|
|
|
* |
435
|
|
|
* @param \Aimeos\Base\MQueue\Manager\Iface $mqManager Message queue manager object |
436
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
437
|
|
|
*/ |
438
|
|
|
public function setMessageQueueManager( \Aimeos\Base\MQueue\Manager\Iface $mqManager ) : \Aimeos\MShop\ContextIface |
439
|
|
|
{ |
440
|
|
|
$this->queue = $mqManager; |
441
|
|
|
|
442
|
|
|
return $this; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Returns the message queue object. |
448
|
|
|
* |
449
|
|
|
* @param string $resource Resource name, e.g. "mq-email" |
450
|
|
|
* @param string $queue Message queue name, e.g. "order/email/payment" |
451
|
|
|
* @return \Aimeos\Base\MQueue\Queue\Iface Message queue object |
452
|
|
|
*/ |
453
|
|
|
public function queue( string $resource, string $queue ) : \Aimeos\Base\MQueue\Queue\Iface |
454
|
|
|
{ |
455
|
|
|
if( !isset( $this->queue ) ) { |
456
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Message queue object not available' ) ); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
return $this->queue->get( $resource )->getQueue( $queue ); |
|
|
|
|
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Returns the nonce value for inline Javascript |
465
|
|
|
* |
466
|
|
|
* @return string|null Nonce value |
467
|
|
|
*/ |
468
|
|
|
public function nonce() : ?string |
469
|
|
|
{ |
470
|
|
|
return $this->nonce; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
|
474
|
|
|
/** |
475
|
|
|
* Sets the nonce value for inline Javascript |
476
|
|
|
* |
477
|
|
|
* @param string $value Nonce value |
478
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
479
|
|
|
*/ |
480
|
|
|
public function setNonce( ?string $value ) : \Aimeos\MShop\ContextIface |
481
|
|
|
{ |
482
|
|
|
$this->nonce = $value; |
483
|
|
|
return $this; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* Returns the password adapter object. |
489
|
|
|
* |
490
|
|
|
* @return \Aimeos\Base\Password\Iface Password adapter |
491
|
|
|
*/ |
492
|
|
|
public function password() : \Aimeos\Base\Password\Iface |
493
|
|
|
{ |
494
|
|
|
if( !isset( $this->password ) ) { |
495
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Password object not available' ) ); |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
return $this->password; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
|
502
|
|
|
/** |
503
|
|
|
* Sets the password adapter object. |
504
|
|
|
* |
505
|
|
|
* @param \Aimeos\Base\Password\Iface $password Password adapter |
506
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
507
|
|
|
*/ |
508
|
|
|
public function setPassword( \Aimeos\Base\Password\Iface $password ) : \Aimeos\MShop\ContextIface |
509
|
|
|
{ |
510
|
|
|
$this->password = $password; |
511
|
|
|
return $this; |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* Sets the process object. |
517
|
|
|
* |
518
|
|
|
* @param \Aimeos\Base\Process\Iface $process Process object |
519
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
520
|
|
|
*/ |
521
|
|
|
public function setProcess( \Aimeos\Base\Process\Iface $process ) : \Aimeos\MShop\ContextIface |
522
|
|
|
{ |
523
|
|
|
$this->process = $process; |
524
|
|
|
|
525
|
|
|
return $this; |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
|
529
|
|
|
/** |
530
|
|
|
* Returns the process object. |
531
|
|
|
* |
532
|
|
|
* @return \Aimeos\Base\Process\Iface Process object |
533
|
|
|
*/ |
534
|
|
|
public function process() : \Aimeos\Base\Process\Iface |
535
|
|
|
{ |
536
|
|
|
if( !isset( $this->process ) ) { |
537
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Process object not available' ) ); |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
return $this->process; |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
|
544
|
|
|
/** |
545
|
|
|
* Sets the session object. |
546
|
|
|
* |
547
|
|
|
* @param \Aimeos\Base\Session\Iface $session Session object |
548
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
549
|
|
|
*/ |
550
|
|
|
public function setSession( \Aimeos\Base\Session\Iface $session ) : \Aimeos\MShop\ContextIface |
551
|
|
|
{ |
552
|
|
|
$this->session = $session; |
553
|
|
|
|
554
|
|
|
return $this; |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
|
558
|
|
|
/** |
559
|
|
|
* Returns the session object. |
560
|
|
|
* |
561
|
|
|
* @return \Aimeos\Base\Session\Iface Session object |
562
|
|
|
*/ |
563
|
|
|
public function session() : \Aimeos\Base\Session\Iface |
564
|
|
|
{ |
565
|
|
|
if( !isset( $this->session ) ) { |
566
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'Session object not available' ) ); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
return $this->session; |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
/** |
573
|
|
|
* Returns the session token. |
574
|
|
|
* |
575
|
|
|
* @return string|null Session token |
576
|
|
|
*/ |
577
|
|
|
public function token() : ?string |
578
|
|
|
{ |
579
|
|
|
return $this->token; |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
|
583
|
|
|
/** |
584
|
|
|
* Sets the ion token. |
585
|
|
|
* |
586
|
|
|
* @param string $token Session token |
587
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
588
|
|
|
*/ |
589
|
|
|
public function setToken( string $token ) : \Aimeos\MShop\ContextIface |
590
|
|
|
{ |
591
|
|
|
$this->token = $token; |
592
|
|
|
return $this; |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
|
596
|
|
|
/** |
597
|
|
|
* Sets the view object. |
598
|
|
|
* |
599
|
|
|
* @param \Aimeos\Base\View\Iface $view View object |
600
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
601
|
|
|
*/ |
602
|
|
|
public function setView( \Aimeos\Base\View\Iface $view ) : \Aimeos\MShop\ContextIface |
603
|
|
|
{ |
604
|
|
|
$this->view = $view; |
605
|
|
|
|
606
|
|
|
return $this; |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
|
610
|
|
|
/** |
611
|
|
|
* Returns the view object. |
612
|
|
|
* |
613
|
|
|
* @return \Aimeos\Base\View\Iface View object |
614
|
|
|
*/ |
615
|
|
|
public function view() : \Aimeos\Base\View\Iface |
616
|
|
|
{ |
617
|
|
|
if( !isset( $this->view ) ) { |
618
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'View object not available' ) ); |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
return clone $this->view; |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
|
625
|
|
|
/** |
626
|
|
|
* Sets the account name of the user/editor. |
627
|
|
|
* |
628
|
|
|
* @param string $name Account name of the user/editor |
629
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
630
|
|
|
*/ |
631
|
|
|
public function setEditor( string $name ) : \Aimeos\MShop\ContextIface |
632
|
|
|
{ |
633
|
|
|
$this->editor = $name; |
634
|
|
|
|
635
|
|
|
return $this; |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* Returns the account name of the user/editor. |
641
|
|
|
* |
642
|
|
|
* @return string Account name of the user/editor |
643
|
|
|
*/ |
644
|
|
|
public function editor() : string |
645
|
|
|
{ |
646
|
|
|
return $this->editor; |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* Returns the user/customer item of the logged in user. |
652
|
|
|
* |
653
|
|
|
* @return \Aimeos\MShop\Customer\Item\Iface|null User/customer item of the logged in user |
654
|
|
|
*/ |
655
|
|
|
public function user() : ?\Aimeos\MShop\Customer\Item\Iface |
656
|
|
|
{ |
657
|
|
|
if( $this->user instanceof \Closure ) |
658
|
|
|
{ |
659
|
|
|
$fcn = $this->user; |
660
|
|
|
$this->user = $fcn(); |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
return $this->user; |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
|
667
|
|
|
/** |
668
|
|
|
* Sets the user/customer item of the logged in user. |
669
|
|
|
* |
670
|
|
|
* @param \Closure|string|null $user User/customer item of the logged in user or closure to retrieve them |
671
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
672
|
|
|
*/ |
673
|
|
|
public function setUser( $user ) : \Aimeos\MShop\ContextIface |
674
|
|
|
{ |
675
|
|
|
$this->user = $user; |
676
|
|
|
|
677
|
|
|
return $this; |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
|
681
|
|
|
/** |
682
|
|
|
* Returns the group ID/code pairs of the logged in user. |
683
|
|
|
* |
684
|
|
|
* @return array Group ID/code pairs of the logged in user |
685
|
|
|
*/ |
686
|
|
|
public function groups() : array |
687
|
|
|
{ |
688
|
|
|
if( $this->groups instanceof \Closure ) |
689
|
|
|
{ |
690
|
|
|
$fcn = $this->groups; |
691
|
|
|
$this->groups = $fcn(); |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
return (array) $this->groups; |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
|
698
|
|
|
/** |
699
|
|
|
* Sets the group IDs of the logged in user. |
700
|
|
|
* |
701
|
|
|
* @param \Closure|array $groups Group ID/code pairs of the logged in user or closure to retrieve them |
702
|
|
|
* @return \Aimeos\MShop\ContextIface Context item for chaining method calls |
703
|
|
|
*/ |
704
|
|
|
public function setGroups( $groups ) : \Aimeos\MShop\ContextIface |
705
|
|
|
{ |
706
|
|
|
$this->groups = $groups; |
707
|
|
|
|
708
|
|
|
return $this; |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
|
712
|
|
|
/** |
713
|
|
|
* Returns a hash for the given objects |
714
|
|
|
* |
715
|
|
|
* @param array $list List of objects |
716
|
|
|
* @return string Hash for the objects |
717
|
|
|
*/ |
718
|
|
|
private function hash( array $list ) : string |
719
|
|
|
{ |
720
|
|
|
$hash = ''; |
721
|
|
|
|
722
|
|
|
foreach( $list as $item ) |
723
|
|
|
{ |
724
|
|
|
if( is_object( $item ) ) { |
725
|
|
|
$hash .= spl_object_hash( $item ); |
726
|
|
|
} |
727
|
|
|
} |
728
|
|
|
|
729
|
|
|
return $hash; |
730
|
|
|
} |
731
|
|
|
} |
732
|
|
|
|
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.