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