1 | <?php |
||
22 | class Context |
||
23 | { |
||
24 | /** |
||
25 | * @var \Aimeos\MShop\Context\Item\Iface |
||
26 | */ |
||
27 | private $context; |
||
28 | |||
29 | /** |
||
30 | * @var \Aimeos\Shop\Base\Config |
||
31 | */ |
||
32 | private $config; |
||
33 | |||
34 | /** |
||
35 | * @var \Aimeos\Shop\Base\I18n |
||
36 | */ |
||
37 | private $i18n; |
||
38 | |||
39 | /** |
||
40 | * @var \Aimeos\Shop\Base\Locale |
||
41 | */ |
||
42 | private $locale; |
||
43 | |||
44 | /** |
||
45 | * @var \Illuminate\Session\Store |
||
46 | */ |
||
47 | private $session; |
||
48 | |||
49 | |||
50 | /** |
||
51 | * Initializes the object |
||
52 | * |
||
53 | * @param \Illuminate\Session\Store $session Laravel session object |
||
54 | * @param \Aimeos\Shop\Base\Config $config Configuration object |
||
55 | * @param \Aimeos\Shop\Base\Locale $locale Locale object |
||
56 | * @param \Aimeos\Shop\Base\I18n $i18n Internationalisation object |
||
57 | */ |
||
58 | public function __construct( \Illuminate\Session\Store $session, \Aimeos\Shop\Base\Config $config, \Aimeos\Shop\Base\Locale $locale, \Aimeos\Shop\Base\I18n $i18n ) |
||
65 | |||
66 | |||
67 | /** |
||
68 | * Returns the current context |
||
69 | * |
||
70 | * @param boolean $locale True to add locale object to context, false if not (deprecated, use \Aimeos\Shop\Base\Locale) |
||
71 | * @param string $type Configuration type, i.e. "frontend" or "backend" (deprecated, use \Aimeos\Shop\Base\Config) |
||
72 | * @return \Aimeos\MShop\Context\Item\Iface Context object |
||
73 | */ |
||
74 | public function get( $locale = true, $type = 'frontend' ) |
||
108 | |||
109 | |||
110 | /** |
||
111 | * Adds the cache object to the context |
||
112 | * |
||
113 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object including config |
||
114 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
115 | */ |
||
116 | protected function addCache( \Aimeos\MShop\Context\Item\Iface $context ) |
||
122 | |||
123 | |||
124 | /** |
||
125 | * Adds the database manager object to the context |
||
126 | * |
||
127 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
128 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
129 | */ |
||
130 | protected function addDatabaseManager( \Aimeos\MShop\Context\Item\Iface $context ) |
||
136 | |||
137 | |||
138 | /** |
||
139 | * Adds the filesystem manager object to the context |
||
140 | * |
||
141 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
142 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
143 | */ |
||
144 | protected function addFilesystemManager( \Aimeos\MShop\Context\Item\Iface $context ) |
||
153 | |||
154 | |||
155 | /** |
||
156 | * Adds the logger object to the context |
||
157 | * |
||
158 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
159 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
160 | */ |
||
161 | protected function addLogger( \Aimeos\MShop\Context\Item\Iface $context ) |
||
167 | |||
168 | |||
169 | |||
170 | /** |
||
171 | * Adds the mailer object to the context |
||
172 | * |
||
173 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
174 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
175 | */ |
||
176 | protected function addMailer( \Aimeos\MShop\Context\Item\Iface $context ) |
||
182 | |||
183 | |||
184 | /** |
||
185 | * Adds the message queue manager object to the context |
||
186 | * |
||
187 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
188 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
189 | */ |
||
190 | protected function addMessageQueueManager( \Aimeos\MShop\Context\Item\Iface $context ) |
||
196 | |||
197 | |||
198 | /** |
||
199 | * Adds the process object to the context |
||
200 | * |
||
201 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
202 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
203 | */ |
||
204 | protected function addProcess( \Aimeos\MShop\Context\Item\Iface $context ) |
||
215 | |||
216 | |||
217 | /** |
||
218 | * Adds the session object to the context |
||
219 | * |
||
220 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
221 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
222 | */ |
||
223 | protected function addSession( \Aimeos\MShop\Context\Item\Iface $context ) |
||
229 | |||
230 | |||
231 | /** |
||
232 | * Adds the user ID and name if available |
||
233 | * |
||
234 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
235 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
236 | */ |
||
237 | protected function addUser( \Aimeos\MShop\Context\Item\Iface $context ) |
||
238 | { |
||
239 | if( ( $userid = Auth::id() ) !== null ) { |
||
240 | $context->setUserId( $userid ); |
||
241 | } |
||
242 | |||
243 | if( ( $user = Auth::user() ) !== null ) { |
||
244 | $context->setEditor( $user->name ); |
||
245 | } else { |
||
246 | $context->setEditor( \Request::ip() ); |
||
247 | } |
||
248 | |||
249 | return $context; |
||
250 | } |
||
251 | |||
252 | |||
253 | /** |
||
254 | * Adds the group IDs if available |
||
255 | * |
||
256 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
257 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
258 | */ |
||
259 | protected function addGroups( \Aimeos\MShop\Context\Item\Iface $context ) |
||
272 | } |
||
273 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.