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\ContextIface $context Context object |
51
|
|
|
* @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
52
|
|
|
*/ |
53
|
|
|
public function get( \Aimeos\MShop\ContextIface $context ) : \Aimeos\MShop\Locale\Item\Iface |
54
|
|
|
{ |
55
|
|
|
if( $this->locale === null ) |
56
|
|
|
{ |
57
|
|
|
$site = Request::input( 'site', config( 'shop.mshop.locale.site', 'default' ) ); |
|
|
|
|
58
|
|
|
$lang = Request::input( 'locale', app()->getLocale() ); |
|
|
|
|
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\ContextIface $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\ContextIface $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
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.