|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016 |
|
6
|
|
|
* @package Slim |
|
7
|
|
|
* @subpackage Base |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\Slim\Base; |
|
11
|
|
|
|
|
12
|
|
|
use Psr\Container\ContainerInterface; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Service providing the locale objects |
|
17
|
|
|
* |
|
18
|
|
|
* @package Slim |
|
19
|
|
|
* @subpackage Base |
|
20
|
|
|
*/ |
|
21
|
|
|
class Locale |
|
22
|
|
|
{ |
|
23
|
|
|
private $container; |
|
24
|
|
|
private $locale; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Initializes the object |
|
29
|
|
|
* |
|
30
|
|
|
* @param ContainerInterface $container Dependency container |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( ContainerInterface $container ) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->container = $container; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Returns the locale item for the current request |
|
40
|
|
|
* |
|
41
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
|
42
|
|
|
* @param array $attributes Associative list of URL parameter |
|
43
|
|
|
* @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
|
44
|
|
|
*/ |
|
45
|
|
|
public function get( \Aimeos\MShop\Context\Item\Iface $context, array $attributes ) : \Aimeos\MShop\Locale\Item\Iface |
|
46
|
|
|
{ |
|
47
|
|
|
if( $this->locale === null ) |
|
48
|
|
|
{ |
|
49
|
|
|
$disableSites = $this->container->get( 'aimeos.config' )->get()->get( 'disableSites', true ); |
|
50
|
|
|
|
|
51
|
|
|
$site = ( isset( $attributes['site'] ) ? $attributes['site'] : 'default' ); |
|
52
|
|
|
$lang = ( isset( $attributes['locale'] ) ? $attributes['locale'] : '' ); |
|
53
|
|
|
$currency = ( isset( $attributes['currency'] ) ? $attributes['currency'] : '' ); |
|
54
|
|
|
|
|
55
|
|
|
$localeManager = \Aimeos\MShop::create( $context, 'locale' ); |
|
56
|
|
|
$this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites ); |
|
|
|
|
|
|
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, string $site ) : \Aimeos\MShop\Locale\Item\Iface |
|
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
|
|
|
|