Issues (75)

src/Aimeos/Shop/Base/Locale.php (1 issue)

1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2016
6
 * @package laravel
7
 * @subpackage Base
8
 */
9
10
namespace Aimeos\Shop\Base;
11
12
13
use Illuminate\Support\Facades\Request;
14
use Illuminate\Support\Facades\Route;
15
16
17
/**
18
 * Service providing the context objects
19
 *
20
 * @package laravel
21
 * @subpackage Base
22
 */
23
class Locale
24
{
25
	/**
26
	 * @var \Illuminate\Contracts\Config\Repository
27
	 */
28
	private $config;
29
30
	/**
31
	 * @var \Aimeos\MShop\Locale\Item\Iface
32
	 */
33
	private $locale;
34
35
36
	/**
37
	 * Initializes the object
38
	 *
39
	 * @param \Illuminate\Contracts\Config\Repository $config Configuration object
40
	 */
41
	public function __construct( \Illuminate\Contracts\Config\Repository $config )
42
	{
43
		$this->config = $config;
44
	}
45
46
47
	/**
48
	 * Returns the locale item for the current request
49
	 *
50
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
51
	 * @return \Aimeos\MShop\Locale\Item\Iface Locale item object
52
	 */
53
	public function get( \Aimeos\MShop\Context\Item\Iface $context ) : \Aimeos\MShop\Locale\Item\Iface
54
	{
55
		if( $this->locale === null )
56
		{
57
			$site = Request::input( 'site', 'default' );
58
			$lang = Request::input( 'locale', app()->getLocale() );
0 ignored issues
show
The method getLocale() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

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