1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015 |
6
|
|
|
* @package laravel |
7
|
|
|
* @subpackage Base |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Aimeos\Shop\Base; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Service providing the context objects |
15
|
|
|
* |
16
|
|
|
* @package laravel |
17
|
|
|
* @subpackage Base |
18
|
|
|
*/ |
19
|
|
|
class Context |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \Aimeos\MShop\Context\Item\Iface |
23
|
|
|
*/ |
24
|
|
|
private static $context; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \Illuminate\Contracts\Config\Repository |
28
|
|
|
*/ |
29
|
|
|
private $config; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \Aimeos\MShop\Locale\Item\Iface |
33
|
|
|
*/ |
34
|
|
|
private $locale; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var \Illuminate\Session\Store |
38
|
|
|
*/ |
39
|
|
|
private $session; |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Initializes the object |
44
|
|
|
* |
45
|
|
|
* @param \Illuminate\Contracts\Config\Repository $config Configuration object |
46
|
|
|
* @param \Illuminate\Session\Store $session Laravel session object |
47
|
|
|
*/ |
48
|
|
|
public function __construct( \Illuminate\Contracts\Config\Repository $config, \Illuminate\Session\Store $session ) |
49
|
|
|
{ |
50
|
|
|
$this->config = $config; |
51
|
|
|
$this->session = $session; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns the current context |
57
|
|
|
* |
58
|
|
|
* @param boolean $locale True to add locale object to context, false if not |
59
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context object |
60
|
|
|
*/ |
61
|
|
|
public function get( $locale = true ) |
62
|
|
|
{ |
63
|
|
|
if( self::$context === null ) |
64
|
|
|
{ |
65
|
|
|
$context = new \Aimeos\MShop\Context\Item\Standard(); |
66
|
|
|
|
67
|
|
|
$config = $this->getConfig(); |
68
|
|
|
$context->setConfig( $config ); |
69
|
|
|
|
70
|
|
|
$dbm = new \Aimeos\MW\DB\Manager\PDO( $config ); |
71
|
|
|
$context->setDatabaseManager( $dbm ); |
72
|
|
|
|
73
|
|
|
$fs = new \Aimeos\MW\Filesystem\Manager\Laravel( app( 'filesystem' ), $config, storage_path( 'aimeos' ) ); |
74
|
|
|
$context->setFilesystemManager( $fs ); |
75
|
|
|
|
76
|
|
|
$mail = new \Aimeos\MW\Mail\Swift( function() { return app( 'mailer' )->getSwiftMailer(); } ); |
77
|
|
|
$context->setMail( $mail ); |
78
|
|
|
|
79
|
|
|
$logger = \Aimeos\MAdmin\Log\Manager\Factory::createManager( $context ); |
80
|
|
|
$context->setLogger( $logger ); |
81
|
|
|
|
82
|
|
|
$cache = new \Aimeos\MAdmin\Cache\Proxy\Standard( $context ); |
83
|
|
|
$context->setCache( $cache ); |
84
|
|
|
|
85
|
|
|
self::$context = $context; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$context = self::$context; |
89
|
|
|
|
90
|
|
|
if( $locale === true ) |
91
|
|
|
{ |
92
|
|
|
$localeItem = $this->getLocale( $context ); |
93
|
|
|
$langid = $localeItem->getLanguageId(); |
94
|
|
|
|
95
|
|
|
$context->setLocale( $localeItem ); |
96
|
|
|
$context->setI18n( app('\Aimeos\Shop\Base\I18n')->get( array( $langid ) ) ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$session = new \Aimeos\MW\Session\Laravel4( $this->session ); |
100
|
|
|
$context->setSession( $session ); |
101
|
|
|
|
102
|
|
|
$this->addUser( $context ); |
103
|
|
|
|
104
|
|
|
return $context; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Adds the user ID and name if available |
110
|
|
|
* |
111
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
112
|
|
|
*/ |
113
|
|
|
protected function addUser( \Aimeos\MShop\Context\Item\Iface $context ) |
114
|
|
|
{ |
115
|
|
|
if( ( $userid = \Auth::id() ) !== null ) |
116
|
|
|
{ |
117
|
|
|
$context->setUserId( $userid ); |
118
|
|
|
$context->setGroupIds( function() use ( $context, $userid ) |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $context, 'customer' ); |
121
|
|
|
return $manager->getItem( $userid, array( 'customer/group' ) )->getGroups(); |
122
|
|
|
} ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
if( ( $user = \Auth::user() ) !== null ) { |
126
|
|
|
$context->setEditor( $user->name ); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Creates a new configuration object. |
133
|
|
|
* |
134
|
|
|
* @return \Aimeos\MW\Config\Iface Configuration object |
135
|
|
|
*/ |
136
|
|
|
protected function getConfig() |
137
|
|
|
{ |
138
|
|
|
$conf = $this->config->get( 'shop' ); |
139
|
|
|
|
140
|
|
|
$configPaths = app( '\Aimeos\Shop\Base\Aimeos' )->get()->getConfigPaths( 'mysql' ); |
141
|
|
|
$config = new \Aimeos\MW\Config\PHPArray( $conf, $configPaths ); |
142
|
|
|
|
143
|
|
|
if( function_exists( 'apc_store' ) === true && $this->config->get( 'shop.apc_enabled', false ) == true ) { |
144
|
|
|
$config = new \Aimeos\MW\Config\Decorator\APC( $config, $this->config->get( 'shop.apc_prefix', 'laravel:' ) ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return $config; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Returns the locale item for the current request |
153
|
|
|
* |
154
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $context Context object |
155
|
|
|
* @return \Aimeos\MShop\Locale\Item\Iface Locale item object |
156
|
|
|
*/ |
157
|
|
|
protected function getLocale( \Aimeos\MShop\Context\Item\Iface $context ) |
158
|
|
|
{ |
159
|
|
|
if( $this->locale === null ) |
160
|
|
|
{ |
161
|
|
|
if( \Route::current() !== null ) |
162
|
|
|
{ |
163
|
|
|
$site = \Route::input( 'site', 'default' ); |
164
|
|
|
$lang = \Route::input( 'locale', '' ); |
165
|
|
|
$currency = \Route::input( 'currency', '' ); |
166
|
|
|
} |
167
|
|
|
else |
168
|
|
|
{ |
169
|
|
|
$site = 'default'; |
170
|
|
|
$lang = $currency = ''; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$disableSites = $this->config->has( 'shop.disableSites' ); |
174
|
|
|
|
175
|
|
|
$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $context ); |
176
|
|
|
$this->locale = $localeManager->bootstrap( $site, $lang, $currency, $disableSites ); |
|
|
|
|
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
return $this->locale; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: