1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * @license MIT, http://opensource.org/licenses/MIT |
||||
5 | * @copyright Aimeos (aimeos.org), 2015-2023 |
||||
6 | */ |
||||
7 | |||||
8 | namespace Aimeos\Shop\Base; |
||||
9 | |||||
10 | |||||
11 | use Illuminate\Support\Facades\Request; |
||||
12 | use Illuminate\Support\Facades\Route; |
||||
13 | |||||
14 | |||||
15 | /** |
||||
16 | * Service providing the context objects |
||||
17 | */ |
||||
18 | class Locale |
||||
19 | { |
||||
20 | /** |
||||
21 | * @var \Illuminate\Contracts\Config\Repository |
||||
22 | */ |
||||
23 | private $config; |
||||
24 | |||||
25 | /** |
||||
26 | * @var \Aimeos\MShop\Locale\Item\Iface |
||||
27 | */ |
||||
28 | private $locale; |
||||
29 | |||||
30 | |||||
31 | /** |
||||
32 | * Initializes the object |
||||
33 | * |
||||
34 | * @param \Illuminate\Contracts\Config\Repository $config Configuration object |
||||
35 | */ |
||||
36 | public function __construct( \Illuminate\Contracts\Config\Repository $config ) |
||||
37 | { |
||||
38 | $this->config = $config; |
||||
39 | } |
||||
40 | |||||
41 | |||||
42 | /** |
||||
43 | * Returns the locale item for the current request |
||||
44 | * |
||||
45 | * @param \Aimeos\MShop\ContextIface $context Context object |
||||
46 | * @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
||||
47 | */ |
||||
48 | public function get( \Aimeos\MShop\ContextIface $context ) : \Aimeos\MShop\Locale\Item\Iface |
||||
49 | { |
||||
50 | if( $this->locale === null ) |
||||
51 | { |
||||
52 | $site = config( 'shop.mshop.locale.site', 'default' ); |
||||
0 ignored issues
–
show
'shop.mshop.locale.site' of type string is incompatible with the type array expected by parameter $options of config() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
53 | $lang = app()->getLocale(); |
||||
54 | $currency = ''; |
||||
55 | |||||
56 | if( Route::current() ) |
||||
57 | { |
||||
58 | $site = Request::route( 'site', $site ); |
||||
59 | $lang = Request::route( 'locale', $lang ); |
||||
60 | $currency = Request::route( 'currency', $currency ); |
||||
61 | } |
||||
62 | |||||
63 | $site = Request::input( 'site', $site ); |
||||
64 | $lang = Request::input( 'locale', $lang ); |
||||
65 | $currency = Request::input( 'currency', $currency ); |
||||
66 | |||||
67 | $localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
||||
68 | $disableSites = $this->config->get( 'shop.disableSites', true ); |
||||
69 | |||||
70 | $this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites ); |
||||
71 | } |
||||
72 | |||||
73 | return $this->locale; |
||||
74 | } |
||||
75 | |||||
76 | |||||
77 | /** |
||||
78 | * Returns the locale item for the current request |
||||
79 | * |
||||
80 | * @param \Aimeos\MShop\ContextIface $context Context object |
||||
81 | * @param string $site Unique site code |
||||
82 | * @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
||||
83 | */ |
||||
84 | public function getBackend( \Aimeos\MShop\ContextIface $context, string $site ) : \Aimeos\MShop\Locale\Item\Iface |
||||
85 | { |
||||
86 | $localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
||||
87 | |||||
88 | try { |
||||
89 | $localeItem = $localeManager->bootstrap( $site, '', '', false, null, true ); |
||||
90 | } catch( \Aimeos\MShop\Exception $e ) { |
||||
91 | $localeItem = $localeManager->create(); |
||||
92 | } |
||||
93 | |||||
94 | return $localeItem->setCurrencyId( null )->setLanguageId( null ); |
||||
95 | } |
||||
96 | } |
||||
97 |
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.