| Total Complexity | 104 |
| Total Lines | 899 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class Standard implements \Aimeos\MShop\Context\Item\Iface |
||
| 22 | { |
||
| 23 | private $cache; |
||
| 24 | private $config; |
||
| 25 | private $datetime; |
||
| 26 | private $db; |
||
| 27 | private $fs; |
||
| 28 | private $locale; |
||
| 29 | private $logger; |
||
| 30 | private $mail; |
||
| 31 | private $nonce; |
||
| 32 | private $queue; |
||
| 33 | private $password; |
||
| 34 | private $process; |
||
| 35 | private $session; |
||
| 36 | private $view; |
||
| 37 | private $user; |
||
| 38 | private $groups; |
||
| 39 | private $editor = ''; |
||
| 40 | private $i18n = []; |
||
| 41 | |||
| 42 | |||
| 43 | /** |
||
| 44 | * Cleans up the stored resources |
||
| 45 | */ |
||
| 46 | public function __destruct() |
||
| 47 | { |
||
| 48 | $this->cache = null; |
||
| 49 | $this->config = null; |
||
| 50 | $this->db = null; |
||
| 51 | $this->fs = null; |
||
| 52 | $this->locale = null; |
||
| 53 | $this->logger = null; |
||
| 54 | $this->mail = null; |
||
| 55 | $this->queue = null; |
||
| 56 | $this->password = null; |
||
| 57 | $this->process = null; |
||
| 58 | $this->session = null; |
||
| 59 | $this->view = null; |
||
| 60 | $this->i18n = []; |
||
| 61 | } |
||
| 62 | |||
| 63 | |||
| 64 | /** |
||
| 65 | * Clones internal objects of the context item. |
||
| 66 | */ |
||
| 67 | public function __clone() |
||
| 68 | { |
||
| 69 | $this->cache = ( isset( $this->cache ) ? clone $this->cache : null ); |
||
| 70 | $this->config = ( isset( $this->config ) ? clone $this->config : null ); |
||
| 71 | $this->fs = ( isset( $this->fs ) ? clone $this->fs : null ); |
||
| 72 | $this->locale = ( isset( $this->locale ) ? clone $this->locale : null ); |
||
| 73 | $this->logger = ( isset( $this->logger ) ? clone $this->logger : null ); |
||
| 74 | $this->mail = ( isset( $this->mail ) ? clone $this->mail : null ); |
||
| 75 | $this->queue = ( isset( $this->queue ) ? clone $this->queue : null ); |
||
| 76 | $this->password = ( isset( $this->password ) ? clone $this->password : null ); |
||
| 77 | $this->process = ( isset( $this->process ) ? clone $this->process : null ); |
||
| 78 | $this->session = ( isset( $this->session ) ? clone $this->session : null ); |
||
| 79 | // view is always cloned |
||
| 80 | |||
| 81 | foreach( $this->i18n as $locale => $object ) { |
||
| 82 | $this->i18n[$locale] = clone $this->i18n[$locale]; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | |||
| 87 | /** |
||
| 88 | * Cleans up internal objects of the context item |
||
| 89 | */ |
||
| 90 | public function __sleep() : array |
||
| 91 | { |
||
| 92 | $objects = array( |
||
| 93 | $this->cache, $this->config, $this->db, $this->fs, $this->locale, $this->logger, |
||
| 94 | $this->mail, $this->queue, $this->password, $this->process, $this->session, $this->view |
||
| 95 | ); |
||
| 96 | |||
| 97 | foreach( $objects as $object ) |
||
| 98 | { |
||
| 99 | if( is_object( $object ) && method_exists( $object, '__sleep' ) ) { |
||
| 100 | $object->__sleep(); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | return get_object_vars( $this ); |
||
| 105 | } |
||
| 106 | |||
| 107 | |||
| 108 | /** |
||
| 109 | * Returns a hash identifying the context object. |
||
| 110 | * |
||
| 111 | * @return string Hash for identifying the context object |
||
| 112 | */ |
||
| 113 | public function __toString() : string |
||
| 114 | { |
||
| 115 | $objects = array( |
||
| 116 | $this, $this->cache, $this->config, $this->db, $this->fs, $this->locale, |
||
| 117 | $this->logger, $this->mail, $this->queue, $this->password, $this->process, |
||
| 118 | $this->session, $this->view |
||
| 119 | ); |
||
| 120 | |||
| 121 | return md5( $this->hash( $objects ) ); |
||
| 122 | } |
||
| 123 | |||
| 124 | |||
| 125 | /** |
||
| 126 | * Sets the cache object. |
||
| 127 | * |
||
| 128 | * @param \Aimeos\MW\Cache\Iface $cache Cache object |
||
| 129 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 130 | */ |
||
| 131 | public function setCache( \Aimeos\MW\Cache\Iface $cache ) : \Aimeos\MShop\Context\Item\Iface |
||
| 132 | { |
||
| 133 | $this->cache = $cache; |
||
| 134 | |||
| 135 | return $this; |
||
| 136 | } |
||
| 137 | |||
| 138 | |||
| 139 | /** |
||
| 140 | * Returns the cache object. |
||
| 141 | * |
||
| 142 | * @return \Aimeos\MW\Cache\Iface Cache object |
||
| 143 | */ |
||
| 144 | public function getCache() : \Aimeos\MW\Cache\Iface |
||
| 145 | { |
||
| 146 | if( !isset( $this->cache ) ) { |
||
| 147 | throw new \Aimeos\MShop\Exception( sprintf( 'Cache object not available' ) ); |
||
| 148 | } |
||
| 149 | |||
| 150 | return $this->cache; |
||
| 151 | } |
||
| 152 | |||
| 153 | |||
| 154 | /** |
||
| 155 | * Returns the cache object. |
||
| 156 | * |
||
| 157 | * @return \Aimeos\MW\Cache\Iface Cache object |
||
| 158 | */ |
||
| 159 | public function cache() : \Aimeos\MW\Cache\Iface |
||
| 160 | { |
||
| 161 | return $this->getCache(); |
||
| 162 | } |
||
| 163 | |||
| 164 | |||
| 165 | /** |
||
| 166 | * Sets the configuration object. |
||
| 167 | * |
||
| 168 | * @param \Aimeos\MW\Config\Iface $config Configuration object |
||
| 169 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 170 | */ |
||
| 171 | public function setConfig( \Aimeos\MW\Config\Iface $config ) : \Aimeos\MShop\Context\Item\Iface |
||
| 172 | { |
||
| 173 | $this->config = $config; |
||
| 174 | |||
| 175 | return $this; |
||
| 176 | } |
||
| 177 | |||
| 178 | |||
| 179 | /** |
||
| 180 | * Returns the configuration object. |
||
| 181 | * |
||
| 182 | * @return \Aimeos\MW\Config\Iface Configuration object |
||
| 183 | */ |
||
| 184 | public function getConfig() : \Aimeos\MW\Config\Iface |
||
| 185 | { |
||
| 186 | if( !isset( $this->config ) ) { |
||
| 187 | throw new \Aimeos\MShop\Exception( sprintf( 'Configuration object not available' ) ); |
||
| 188 | } |
||
| 189 | |||
| 190 | return $this->config; |
||
| 191 | } |
||
| 192 | |||
| 193 | |||
| 194 | /** |
||
| 195 | * Returns the configuration object. |
||
| 196 | * |
||
| 197 | * @return \Aimeos\MW\Config\Iface Configuration object |
||
| 198 | */ |
||
| 199 | public function config() : \Aimeos\MW\Config\Iface |
||
| 202 | } |
||
| 203 | |||
| 204 | |||
| 205 | /** |
||
| 206 | * Sets the database connection manager object. |
||
| 207 | * |
||
| 208 | * @param \Aimeos\MW\DB\Manager\Iface $manager Database manager object |
||
| 209 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 210 | */ |
||
| 211 | public function setDatabaseManager( \Aimeos\MW\DB\Manager\Iface $manager ) : \Aimeos\MShop\Context\Item\Iface |
||
| 212 | { |
||
| 213 | $this->db = $manager; |
||
| 214 | |||
| 215 | return $this; |
||
| 216 | } |
||
| 217 | |||
| 218 | |||
| 219 | /** |
||
| 220 | * Returns the database manager object. |
||
| 221 | * |
||
| 222 | * @return \Aimeos\MW\DB\Manager\Iface Database manager object |
||
| 223 | */ |
||
| 224 | public function getDatabaseManager() : \Aimeos\MW\DB\Manager\Iface |
||
| 225 | { |
||
| 226 | if( !isset( $this->db ) ) { |
||
| 227 | throw new \Aimeos\MShop\Exception( sprintf( 'Database manager object not available' ) ); |
||
| 228 | } |
||
| 229 | |||
| 230 | return $this->db; |
||
| 231 | } |
||
| 232 | |||
| 233 | |||
| 234 | /** |
||
| 235 | * Returns the database manager object. |
||
| 236 | * |
||
| 237 | * @return \Aimeos\MW\DB\Manager\Iface Database manager object |
||
| 238 | */ |
||
| 239 | public function db() : \Aimeos\MW\DB\Manager\Iface |
||
| 240 | { |
||
| 241 | return $this->getDatabaseManager(); |
||
| 242 | } |
||
| 243 | |||
| 244 | |||
| 245 | /** |
||
| 246 | * Sets the current date and time |
||
| 247 | * |
||
| 248 | * @param string $datetime Date and time as ISO string (YYYY-MM-DD HH:mm:ss) |
||
| 249 | */ |
||
| 250 | public function setDateTime( string $datetime ) : \Aimeos\MShop\Context\Item\Iface |
||
| 251 | { |
||
| 252 | $regex = '/^[0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]$/'; |
||
| 253 | |||
| 254 | if( preg_match( $regex, (string) $datetime ) !== 1 ) { |
||
| 255 | throw new \Aimeos\MShop\Exception( sprintf( 'Invalid characters in date "%1$s". ISO format "YYYY-MM-DD hh:mm:ss" expected.', $datetime ) ); |
||
| 256 | } |
||
| 257 | |||
| 258 | $this->datetime = $datetime; |
||
| 259 | |||
| 260 | return $this; |
||
| 261 | } |
||
| 262 | |||
| 263 | |||
| 264 | /** |
||
| 265 | * Returns the current date and time |
||
| 266 | * This is especially useful to share the same request time or if applications |
||
| 267 | * allow to travel in time. |
||
| 268 | * |
||
| 269 | * @return string Current date and time as ISO string (YYYY-MM-DD HH:mm:ss) |
||
| 270 | */ |
||
| 271 | public function getDateTime() : string |
||
| 272 | { |
||
| 273 | if( $this->datetime === null ) { |
||
| 274 | $this->datetime = date( 'Y-m-d H:i:00' ); |
||
| 275 | } |
||
| 276 | |||
| 277 | return $this->datetime; |
||
| 278 | } |
||
| 279 | |||
| 280 | |||
| 281 | /** |
||
| 282 | * Returns the current date and time |
||
| 283 | * This is especially useful to share the same request time or if applications |
||
| 284 | * allow to travel in time. |
||
| 285 | * |
||
| 286 | * @return string Current date and time as ISO string (YYYY-MM-DD HH:mm:ss) |
||
| 287 | */ |
||
| 288 | public function datetime() : string |
||
| 289 | { |
||
| 290 | return $this->getDateTime(); |
||
| 291 | } |
||
| 292 | |||
| 293 | |||
| 294 | /** |
||
| 295 | * Sets the file system manager object. |
||
| 296 | * |
||
| 297 | * @param \Aimeos\MW\Filesystem\Manager\Iface $manager File system object |
||
| 298 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 299 | */ |
||
| 300 | public function setFilesystemManager( \Aimeos\MW\Filesystem\Manager\Iface $manager ) : \Aimeos\MShop\Context\Item\Iface |
||
| 301 | { |
||
| 302 | $this->fs = $manager; |
||
| 303 | |||
| 304 | return $this; |
||
| 305 | } |
||
| 306 | |||
| 307 | |||
| 308 | /** |
||
| 309 | * Returns the file system manager object. |
||
| 310 | * |
||
| 311 | * @return \Aimeos\MW\Filesystem\Manager\Iface File system manager object |
||
| 312 | */ |
||
| 313 | public function getFilesystemManager() : \Aimeos\MW\Filesystem\Manager\Iface |
||
| 314 | { |
||
| 315 | if( !isset( $this->fs ) ) { |
||
| 316 | throw new \Aimeos\MShop\Exception( sprintf( 'File system manager object not available' ) ); |
||
| 317 | } |
||
| 318 | |||
| 319 | return $this->fs; |
||
| 320 | } |
||
| 321 | |||
| 322 | |||
| 323 | /** |
||
| 324 | * Returns the file system object for the given resource name. |
||
| 325 | * |
||
| 326 | * @param string $resource Resource name, e.g. "fs-admin" |
||
| 327 | * @return \Aimeos\MW\Filesystem\Iface File system object |
||
| 328 | */ |
||
| 329 | public function getFilesystem( string $resource ) : \Aimeos\MW\Filesystem\Iface |
||
| 330 | { |
||
| 331 | if( !isset( $this->fs ) ) { |
||
| 332 | throw new \Aimeos\MShop\Exception( sprintf( 'File system manager object not available' ) ); |
||
| 333 | } |
||
| 334 | |||
| 335 | return $this->fs->get( $resource ); |
||
| 336 | } |
||
| 337 | |||
| 338 | |||
| 339 | /** |
||
| 340 | * Returns the file system object for the given resource name. |
||
| 341 | * |
||
| 342 | * @param string $resource Resource name, e.g. "fs-admin" |
||
| 343 | * @return \Aimeos\MW\Filesystem\Iface File system object |
||
| 344 | */ |
||
| 345 | public function fs( string $resource ) : \Aimeos\MW\Filesystem\Iface |
||
| 346 | { |
||
| 347 | return $this->getFilesystem( $resource ); |
||
| 348 | } |
||
| 349 | |||
| 350 | |||
| 351 | /** |
||
| 352 | * Sets the translation/internationalization objects. |
||
| 353 | * |
||
| 354 | * @param array $translations Associative list of internationalization objects implementing |
||
| 355 | * \Aimeos\MW\Translation\Iface with locale as key |
||
| 356 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 357 | */ |
||
| 358 | public function setI18n( array $translations ) : \Aimeos\MShop\Context\Item\Iface |
||
| 359 | { |
||
| 360 | $this->i18n = $translations; |
||
| 361 | |||
| 362 | return $this; |
||
| 363 | } |
||
| 364 | |||
| 365 | |||
| 366 | /** |
||
| 367 | * Returns the translation/internationalization object for the given locale (null for default one). |
||
| 368 | * |
||
| 369 | * @param string|null $locale Two letter language ISO code for specific language instead of default one |
||
| 370 | * @return \Aimeos\MW\Translation\Iface Internationalization object |
||
| 371 | */ |
||
| 372 | public function getI18n( string $locale = null ) : \Aimeos\MW\Translation\Iface |
||
| 373 | { |
||
| 374 | if( isset( $this->locale ) && $locale === null ) { |
||
| 375 | $locale = $this->getLocale()->getLanguageId(); |
||
| 376 | } |
||
| 377 | |||
| 378 | if( isset( $this->locale ) && $locale === null && reset( $this->i18n ) !== false ) { |
||
| 379 | $locale = key( $this->i18n ); |
||
| 380 | } |
||
| 381 | |||
| 382 | if( isset( $this->i18n[$locale] ) ) { |
||
| 383 | return $this->i18n[$locale]; |
||
| 384 | } |
||
| 385 | |||
| 386 | if( isset( $this->i18n['en'] ) ) { |
||
| 387 | return $this->i18n['en']; |
||
| 388 | } |
||
| 389 | |||
| 390 | /// Locale ID %1$s |
||
| 391 | throw new \Aimeos\MShop\Exception( sprintf( 'Internationalization object not available for "%1$s"', $locale ) ); |
||
| 392 | } |
||
| 393 | |||
| 394 | |||
| 395 | /** |
||
| 396 | * Returns the translation/internationalization object for the given locale (null for default one). |
||
| 397 | * |
||
| 398 | * @param string|null $locale Two letter language ISO code for specific language instead of default one |
||
| 399 | * @return \Aimeos\MW\Translation\Iface Internationalization object |
||
| 400 | */ |
||
| 401 | public function i18n( string $locale = null ) : \Aimeos\MW\Translation\Iface |
||
| 402 | { |
||
| 403 | return $this->getI18n( $locale ); |
||
| 404 | } |
||
| 405 | |||
| 406 | |||
| 407 | /** |
||
| 408 | * Translates a string if possible |
||
| 409 | * |
||
| 410 | * @param string $name Name of the translation domain |
||
| 411 | * @param string $singular Singular string to translate |
||
| 412 | * @param string $plural Plural string to translate if count is not one |
||
| 413 | * @param int $number Number for plural translations |
||
| 414 | * @param string|null $locale Locale (e.g. en, en_US, de, etc.) or NULL for current locale |
||
| 415 | * @return string Translated string if possible |
||
| 416 | */ |
||
| 417 | public function translate( string $domain, string $singular, string $plural = null, int $number = 1, string $locale = null ) : string |
||
| 418 | { |
||
| 419 | if( empty( $this->i18n ) ) { |
||
| 420 | return $number === 1 ? $singular : $plural; |
||
| 421 | } |
||
| 422 | |||
| 423 | if( $plural ) { |
||
| 424 | return $this->i18n( $locale )->dn( $domain, $singular, $plural, $number ); |
||
| 425 | } |
||
| 426 | |||
| 427 | return $this->i18n( $locale )->dt( $domain, $singular ); |
||
| 428 | } |
||
| 429 | |||
| 430 | |||
| 431 | /** |
||
| 432 | * Sets the localization object. |
||
| 433 | * |
||
| 434 | * @param \Aimeos\MShop\Locale\Item\Iface $locale Localization object |
||
| 435 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 436 | */ |
||
| 437 | public function setLocale( \Aimeos\MShop\Locale\Item\Iface $locale ) : \Aimeos\MShop\Context\Item\Iface |
||
| 438 | { |
||
| 439 | $this->locale = $locale; |
||
| 440 | |||
| 441 | return $this; |
||
| 442 | } |
||
| 443 | |||
| 444 | |||
| 445 | /** |
||
| 446 | * Returns the localization object. |
||
| 447 | * |
||
| 448 | * @return \Aimeos\MShop\Locale\Item\Iface Localization object |
||
| 449 | */ |
||
| 450 | public function getLocale() : \Aimeos\MShop\Locale\Item\Iface |
||
| 451 | { |
||
| 452 | if( !isset( $this->locale ) ) { |
||
| 453 | throw new \Aimeos\MShop\Exception( sprintf( 'Locale object not available' ) ); |
||
| 454 | } |
||
| 455 | |||
| 456 | return $this->locale; |
||
| 457 | } |
||
| 458 | |||
| 459 | |||
| 460 | /** |
||
| 461 | * Returns the localization object. |
||
| 462 | * |
||
| 463 | * @return \Aimeos\MShop\Locale\Item\Iface Localization object |
||
| 464 | */ |
||
| 465 | public function locale() : \Aimeos\MShop\Locale\Item\Iface |
||
| 466 | { |
||
| 467 | return $this->getLocale(); |
||
| 468 | } |
||
| 469 | |||
| 470 | |||
| 471 | /** |
||
| 472 | * Sets the logger object. |
||
| 473 | * |
||
| 474 | * @param \Aimeos\MW\Logger\Iface $logger Logger object |
||
| 475 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 476 | */ |
||
| 477 | public function setLogger( \Aimeos\MW\Logger\Iface $logger ) : \Aimeos\MShop\Context\Item\Iface |
||
| 478 | { |
||
| 479 | $this->logger = $logger; |
||
| 480 | |||
| 481 | return $this; |
||
| 482 | } |
||
| 483 | |||
| 484 | |||
| 485 | /** |
||
| 486 | * Returns the logger object. |
||
| 487 | * |
||
| 488 | * @return \Aimeos\MW\Logger\Iface Logger object |
||
| 489 | */ |
||
| 490 | public function getLogger() : \Aimeos\MW\Logger\Iface |
||
| 491 | { |
||
| 492 | if( !isset( $this->logger ) ) { |
||
| 493 | throw new \Aimeos\MShop\Exception( sprintf( 'Log manager object not available' ) ); |
||
| 494 | } |
||
| 495 | |||
| 496 | return $this->logger; |
||
| 497 | } |
||
| 498 | |||
| 499 | |||
| 500 | /** |
||
| 501 | * Returns the logger object. |
||
| 502 | * |
||
| 503 | * @return \Aimeos\MW\Logger\Iface Logger object |
||
| 504 | */ |
||
| 505 | public function logger() : \Aimeos\MW\Logger\Iface |
||
| 506 | { |
||
| 507 | return $this->getLogger(); |
||
| 508 | } |
||
| 509 | |||
| 510 | |||
| 511 | /** |
||
| 512 | * Sets the mail object. |
||
| 513 | * |
||
| 514 | * @param \Aimeos\MW\Mail\Iface $mail Mail object |
||
| 515 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 516 | */ |
||
| 517 | public function setMail( \Aimeos\MW\Mail\Iface $mail ) : \Aimeos\MShop\Context\Item\Iface |
||
| 518 | { |
||
| 519 | $this->mail = $mail; |
||
| 520 | |||
| 521 | return $this; |
||
| 522 | } |
||
| 523 | |||
| 524 | |||
| 525 | /** |
||
| 526 | * Returns the mail object. |
||
| 527 | * |
||
| 528 | * @return \Aimeos\MW\Mail\Iface Mail object |
||
| 529 | */ |
||
| 530 | public function getMail() : \Aimeos\MW\Mail\Iface |
||
| 531 | { |
||
| 532 | if( !isset( $this->mail ) ) { |
||
| 533 | throw new \Aimeos\MShop\Exception( sprintf( 'Mail object not available' ) ); |
||
| 534 | } |
||
| 535 | |||
| 536 | return $this->mail; |
||
| 537 | } |
||
| 538 | |||
| 539 | |||
| 540 | /** |
||
| 541 | * Returns the mail object. |
||
| 542 | * |
||
| 543 | * @return \Aimeos\MW\Mail\Iface Mail object |
||
| 544 | */ |
||
| 545 | public function mail() : \Aimeos\MW\Mail\Iface |
||
| 546 | { |
||
| 547 | return $this->getMail(); |
||
| 548 | } |
||
| 549 | |||
| 550 | |||
| 551 | /** |
||
| 552 | * Sets the message queue manager object. |
||
| 553 | * |
||
| 554 | * @param \Aimeos\MW\MQueue\Manager\Iface $mqManager Message queue manager object |
||
| 555 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 556 | */ |
||
| 557 | public function setMessageQueueManager( \Aimeos\MW\MQueue\Manager\Iface $mqManager ) : \Aimeos\MShop\Context\Item\Iface |
||
| 558 | { |
||
| 559 | $this->queue = $mqManager; |
||
| 560 | |||
| 561 | return $this; |
||
| 562 | } |
||
| 563 | |||
| 564 | |||
| 565 | /** |
||
| 566 | * Returns the message queue manager object. |
||
| 567 | * |
||
| 568 | * @return \Aimeos\MW\MQueue\Manager\Iface Message queue manager object |
||
| 569 | */ |
||
| 570 | public function getMessageQueueManager() : \Aimeos\MW\MQueue\Manager\Iface |
||
| 571 | { |
||
| 572 | if( !isset( $this->queue ) ) { |
||
| 573 | throw new \Aimeos\MShop\Exception( sprintf( 'Message queue object not available' ) ); |
||
| 574 | } |
||
| 575 | |||
| 576 | return $this->queue; |
||
| 577 | } |
||
| 578 | |||
| 579 | |||
| 580 | /** |
||
| 581 | * Returns the message queue object. |
||
| 582 | * |
||
| 583 | * @param string $resource Resource name, e.g. "mq-email" |
||
| 584 | * @param string $queue Message queue name, e.g. "order/email/payment" |
||
| 585 | * @return \Aimeos\MW\MQueue\Queue\Iface Message queue object |
||
| 586 | */ |
||
| 587 | public function getMessageQueue( string $resource, string $queue ) : \Aimeos\MW\MQueue\Queue\Iface |
||
| 594 | } |
||
| 595 | |||
| 596 | |||
| 597 | /** |
||
| 598 | * Returns the message queue object. |
||
| 599 | * |
||
| 600 | * @param string $resource Resource name, e.g. "mq-email" |
||
| 601 | * @param string $queue Message queue name, e.g. "order/email/payment" |
||
| 602 | * @return \Aimeos\MW\MQueue\Queue\Iface Message queue object |
||
| 603 | */ |
||
| 604 | public function queue( string $resource, string $queue ) : \Aimeos\MW\MQueue\Queue\Iface |
||
| 605 | { |
||
| 606 | return $this->getMessageQueue( $resource, $queue ); |
||
| 607 | } |
||
| 608 | |||
| 609 | |||
| 610 | /** |
||
| 611 | * Returns the nonce value for inline Javascript |
||
| 612 | * |
||
| 613 | * @return string|null Nonce value |
||
| 614 | */ |
||
| 615 | public function nonce() : ?string |
||
| 616 | { |
||
| 617 | return $this->nonce; |
||
| 618 | } |
||
| 619 | |||
| 620 | |||
| 621 | /** |
||
| 622 | * Sets the nonce value for inline Javascript |
||
| 623 | * |
||
| 624 | * @param string $value Nonce value |
||
| 625 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 626 | */ |
||
| 627 | public function setNonce( ?string $value ) : \Aimeos\MShop\Context\Item\Iface |
||
| 628 | { |
||
| 629 | $this->nonce = $value; |
||
| 630 | return $this; |
||
| 631 | } |
||
| 632 | |||
| 633 | |||
| 634 | /** |
||
| 635 | * Returns the password adapter object. |
||
| 636 | * |
||
| 637 | * @return \Aimeos\MW\Password\Iface Password adapter |
||
| 638 | */ |
||
| 639 | public function password() : \Aimeos\MW\Password\Iface |
||
| 640 | { |
||
| 641 | if( !isset( $this->password ) ) { |
||
| 642 | throw new \Aimeos\MShop\Exception( sprintf( 'Password object not available' ) ); |
||
| 643 | } |
||
| 644 | |||
| 645 | return $this->password; |
||
| 646 | } |
||
| 647 | |||
| 648 | |||
| 649 | /** |
||
| 650 | * Sets the password adapter object. |
||
| 651 | * |
||
| 652 | * @param \Aimeos\MW\Password\Iface $password Password adapter |
||
| 653 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 654 | */ |
||
| 655 | public function setPassword( \Aimeos\MW\Password\Iface $password ) : \Aimeos\MShop\Context\Item\Iface |
||
| 656 | { |
||
| 657 | $this->password = $password; |
||
| 658 | return $this; |
||
| 659 | } |
||
| 660 | |||
| 661 | |||
| 662 | /** |
||
| 663 | * Sets the process object. |
||
| 664 | * |
||
| 665 | * @param \Aimeos\MW\Process\Iface $process Process object |
||
| 666 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 667 | */ |
||
| 668 | public function setProcess( \Aimeos\MW\Process\Iface $process ) : \Aimeos\MShop\Context\Item\Iface |
||
| 669 | { |
||
| 670 | $this->process = $process; |
||
| 671 | |||
| 672 | return $this; |
||
| 673 | } |
||
| 674 | |||
| 675 | |||
| 676 | /** |
||
| 677 | * Returns the process object. |
||
| 678 | * |
||
| 679 | * @return \Aimeos\MW\Process\Iface Process object |
||
| 680 | */ |
||
| 681 | public function getProcess() : \Aimeos\MW\Process\Iface |
||
| 682 | { |
||
| 683 | if( !isset( $this->process ) ) { |
||
| 684 | throw new \Aimeos\MShop\Exception( sprintf( 'Process object not available' ) ); |
||
| 685 | } |
||
| 686 | |||
| 687 | return $this->process; |
||
| 688 | } |
||
| 689 | |||
| 690 | |||
| 691 | /** |
||
| 692 | * Returns the process object. |
||
| 693 | * |
||
| 694 | * @return \Aimeos\MW\Process\Iface Process object |
||
| 695 | */ |
||
| 696 | public function process() : \Aimeos\MW\Process\Iface |
||
| 697 | { |
||
| 698 | return $this->getProcess(); |
||
| 699 | } |
||
| 700 | |||
| 701 | |||
| 702 | /** |
||
| 703 | * Sets the session object. |
||
| 704 | * |
||
| 705 | * @param \Aimeos\MW\Session\Iface $session Session object |
||
| 706 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 707 | */ |
||
| 708 | public function setSession( \Aimeos\MW\Session\Iface $session ) : \Aimeos\MShop\Context\Item\Iface |
||
| 709 | { |
||
| 710 | $this->session = $session; |
||
| 711 | |||
| 712 | return $this; |
||
| 713 | } |
||
| 714 | |||
| 715 | |||
| 716 | /** |
||
| 717 | * Returns the session object. |
||
| 718 | * |
||
| 719 | * @return \Aimeos\MW\Session\Iface Session object |
||
| 720 | */ |
||
| 721 | public function getSession() : \Aimeos\MW\Session\Iface |
||
| 722 | { |
||
| 723 | if( !isset( $this->session ) ) { |
||
| 724 | throw new \Aimeos\MShop\Exception( sprintf( 'Session object not available' ) ); |
||
| 725 | } |
||
| 726 | |||
| 727 | return $this->session; |
||
| 728 | } |
||
| 729 | |||
| 730 | |||
| 731 | /** |
||
| 732 | * Returns the session object. |
||
| 733 | * |
||
| 734 | * @return \Aimeos\MW\Session\Iface Session object |
||
| 735 | */ |
||
| 736 | public function session() : \Aimeos\MW\Session\Iface |
||
| 737 | { |
||
| 738 | return $this->getSession(); |
||
| 739 | } |
||
| 740 | |||
| 741 | |||
| 742 | /** |
||
| 743 | * Sets the view object. |
||
| 744 | * |
||
| 745 | * @param \Aimeos\MW\View\Iface $view View object |
||
| 746 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 747 | */ |
||
| 748 | public function setView( \Aimeos\MW\View\Iface $view ) : \Aimeos\MShop\Context\Item\Iface |
||
| 753 | } |
||
| 754 | |||
| 755 | |||
| 756 | /** |
||
| 757 | * Returns the view object. |
||
| 758 | * |
||
| 759 | * @return \Aimeos\MW\View\Iface View object |
||
| 760 | */ |
||
| 761 | public function getView() : \Aimeos\MW\View\Iface |
||
| 762 | { |
||
| 763 | if( !isset( $this->view ) ) { |
||
| 764 | throw new \Aimeos\MShop\Exception( sprintf( 'View object not available' ) ); |
||
| 765 | } |
||
| 766 | |||
| 767 | return clone $this->view; |
||
| 768 | } |
||
| 769 | |||
| 770 | |||
| 771 | /** |
||
| 772 | * Returns the view object. |
||
| 773 | * |
||
| 774 | * @return \Aimeos\MW\View\Iface View object |
||
| 775 | */ |
||
| 776 | public function view() : \Aimeos\MW\View\Iface |
||
| 777 | { |
||
| 778 | return $this->getView(); |
||
| 779 | } |
||
| 780 | |||
| 781 | |||
| 782 | /** |
||
| 783 | * Sets the account name of the user/editor. |
||
| 784 | * |
||
| 785 | * @param string $name Account name of the user/editor |
||
| 786 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 787 | */ |
||
| 788 | public function setEditor( string $name ) : \Aimeos\MShop\Context\Item\Iface |
||
| 789 | { |
||
| 790 | $this->editor = $name; |
||
| 791 | |||
| 792 | return $this; |
||
| 793 | } |
||
| 794 | |||
| 795 | |||
| 796 | /** |
||
| 797 | * Returns the account name of the user/editor. |
||
| 798 | * |
||
| 799 | * @return string Account name of the user/editor |
||
| 800 | */ |
||
| 801 | public function getEditor() : string |
||
| 802 | { |
||
| 803 | return $this->editor; |
||
| 804 | } |
||
| 805 | |||
| 806 | |||
| 807 | /** |
||
| 808 | * Returns the account name of the user/editor. |
||
| 809 | * |
||
| 810 | * @return string Account name of the user/editor |
||
| 811 | */ |
||
| 812 | public function editor() : string |
||
| 813 | { |
||
| 814 | return $this->editor; |
||
| 815 | } |
||
| 816 | |||
| 817 | |||
| 818 | /** |
||
| 819 | * Sets the user ID of the logged in user. |
||
| 820 | * |
||
| 821 | * @param \Closure|string|null $user User ID of the logged in user or closure to retrieve them |
||
| 822 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 823 | */ |
||
| 824 | public function setUserId( $user ) : \Aimeos\MShop\Context\Item\Iface |
||
| 825 | { |
||
| 826 | $this->user = $user; |
||
| 827 | |||
| 828 | return $this; |
||
| 829 | } |
||
| 830 | |||
| 831 | |||
| 832 | /** |
||
| 833 | * Returns the user ID of the logged in user. |
||
| 834 | * |
||
| 835 | * @return string|null User ID of the logged in user |
||
| 836 | */ |
||
| 837 | public function getUserId() : ?string |
||
| 846 | } |
||
| 847 | |||
| 848 | |||
| 849 | /** |
||
| 850 | * Returns the user ID of the logged in user. |
||
| 851 | * |
||
| 852 | * @return string|null User ID of the logged in user |
||
| 853 | */ |
||
| 854 | public function user() : ?string |
||
| 855 | { |
||
| 856 | return $this->getUserId(); |
||
| 857 | } |
||
| 858 | |||
| 859 | |||
| 860 | /** |
||
| 861 | * Sets the group IDs of the logged in user. |
||
| 862 | * |
||
| 863 | * @param \Closure|array $groupIds Group IDs of the logged in user or closure to retrieve them |
||
| 864 | * @return \Aimeos\MShop\Context\Item\Iface Context item for chaining method calls |
||
| 865 | */ |
||
| 866 | public function setGroupIds( $groupIds ) : \Aimeos\MShop\Context\Item\Iface |
||
| 867 | { |
||
| 868 | $this->groups = $groupIds; |
||
| 869 | |||
| 870 | return $this; |
||
| 871 | } |
||
| 872 | |||
| 873 | |||
| 874 | /** |
||
| 875 | * Returns the group IDs of the logged in user. |
||
| 876 | * |
||
| 877 | * @return array Group IDs of the logged in user |
||
| 878 | */ |
||
| 879 | public function getGroupIds() : array |
||
| 880 | { |
||
| 881 | if( $this->groups instanceof \Closure ) |
||
| 882 | { |
||
| 883 | $fcn = $this->groups; |
||
| 884 | $this->groups = $fcn(); |
||
| 885 | } |
||
| 886 | |||
| 887 | return (array) $this->groups; |
||
| 888 | } |
||
| 889 | |||
| 890 | |||
| 891 | /** |
||
| 892 | * Returns the group IDs of the logged in user. |
||
| 893 | * |
||
| 894 | * @return array Group IDs of the logged in user |
||
| 895 | */ |
||
| 896 | public function groups() : array |
||
| 899 | } |
||
| 900 | |||
| 901 | |||
| 902 | /** |
||
| 903 | * Returns a hash for the given objects |
||
| 904 | * |
||
| 905 | * @param array $list List of objects |
||
| 906 | * @return string Hash for the objects |
||
| 907 | */ |
||
| 908 | private function hash( array $list ) : string |
||
| 909 | { |
||
| 910 | $hash = ''; |
||
| 911 | |||
| 912 | foreach( $list as $item ) |
||
| 913 | { |
||
| 914 | if( is_object( $item ) ) { |
||
| 920 | } |
||
| 921 | } |
||
| 922 |