Locale::get()   A
last analyzed

Complexity

Conditions 6
Paths 17

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 9
c 1
b 0
f 0
nc 17
nop 2
dl 0
loc 17
rs 9.2222
1
<?php
2
3
/**
4
 * @license LGPLv3, http://www.gnu.org/copyleft/lgpl.html
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package flow
7
 * @subpackage Base
8
 */
9
10
11
namespace Aimeos\Shop\Base;
12
13
use Neos\Flow\Annotations as Flow;
14
15
16
/**
17
 * Class providing the context object
18
 *
19
 * @package flow
20
 * @subpackage Base
21
 * @Flow\Scope("singleton")
22
 */
23
class Locale
24
{
25
	/**
26
	 * @var \Aimeos\MShop\Locale\Item\Iface
27
	 */
28
	private $locale;
29
30
	/**
31
	 * @var array
32
	 */
33
	private $settings;
34
35
36
	/**
37
	 * Returns the locale item for the current request
38
	 *
39
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
40
	 * @param \Neos\Flow\Mvc\RequestInterface $request Request object
41
	 * @return \Aimeos\MShop\Locale\Item\Iface Locale item object
42
	 */
43
	public function get( \Aimeos\MShop\Context\Item\Iface $context, \Neos\Flow\Mvc\RequestInterface $request )
44
	{
45
		if( $this->locale === null )
46
		{
47
			$params = $request->getArguments();
48
49
			$site = ( isset( $params['site'] ) ? $params['site'] : 'default' );
50
			$lang = ( isset( $params['locale'] ) ? $params['locale'] : '' );
51
			$currency = ( isset( $params['currency'] ) ? $params['currency'] : '' );
52
53
			$disableSites = (bool) ( isset( $this->settings['flow']['disableSites'] ) ? $this->settings['flow']['disableSites'] : true );
54
55
			$localeManager = \Aimeos\MShop::create( $context, 'locale' );
56
			$this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites );
0 ignored issues
show
Bug introduced by
The method bootstrap() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Locale\Manager\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Index\Manager\DBBase or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Price\Manager\Property\Type\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Order\Manager\Base\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Catalog\Manager\Standard or Aimeos\MShop\Locale\Manager\Site\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Price\Manager\Property\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
			/** @scrutinizer ignore-call */ 
57
   $this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites );
Loading history...
57
		}
58
59
		return $this->locale;
60
	}
61
62
63
	/**
64
	 * Returns the locale item for the current request
65
	 *
66
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
67
	 * @param string $site Unique site code
68
	 * @return \Aimeos\MShop\Locale\Item\Iface Locale item object
69
	 */
70
	public function getBackend( \Aimeos\MShop\Context\Item\Iface $context, $site )
71
	{
72
		$localeManager = \Aimeos\MShop::create( $context, 'locale' );
73
74
		try {
75
			$localeItem = $localeManager->bootstrap( $site, '', '', false, null, true );
76
		} catch( \Aimeos\MShop\Exception $e ) {
77
			$localeItem = $localeManager->createItem();
78
		}
79
80
		return $localeItem->setCurrencyId( null )->setLanguageId( null );
81
	}
82
83
84
	/**
85
	 * Inject the settings
86
	 *
87
	 * @param array $settings
88
	 * @return void
89
	 */
90
	public function injectSettings( array $settings )
91
	{
92
		$this->settings = $settings;
93
	}
94
}
95