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' ) |
||
75 | { |
||
76 | $config = $this->config->get( $type ); |
||
77 | |||
78 | if( $this->context === null ) |
||
79 | { |
||
80 | $context = new \Aimeos\MShop\Context\Item\Standard(); |
||
81 | $context->setConfig( $config ); |
||
82 | |||
83 | $this->addDataBaseManager( $context ); |
||
84 | $this->addFilesystemManager( $context ); |
||
85 | $this->addMessageQueueManager( $context ); |
||
86 | $this->addLogger( $context ); |
||
87 | $this->addCache( $context ); |
||
88 | $this->addMailer( $context); |
||
89 | $this->addSession( $context ); |
||
90 | $this->addUser( $context); |
||
91 | $this->addGroups( $context); |
||
92 | |||
93 | $this->context = $context; |
||
94 | } |
||
95 | |||
96 | $this->context->setConfig( $config ); |
||
97 | |||
98 | if( $locale === true ) |
||
99 | { |
||
100 | $localeItem = $this->locale->get( $this->context ); |
||
101 | $this->context->setLocale( $localeItem ); |
||
102 | $this->context->setI18n( $this->i18n->get( array( $localeItem->getLanguageId() ) ) ); |
||
103 | } |
||
104 | |||
105 | return $this->context; |
||
106 | } |
||
107 | |||
108 | |||
109 | /** |
||
110 | * Adds the cache object to the context |
||
111 | * |
||
112 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object including config |
||
113 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
114 | */ |
||
115 | 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 ) |
||
137 | |||
138 | |||
139 | /** |
||
140 | * Adds the filesystem manager object to the context |
||
141 | * |
||
142 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
143 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
144 | */ |
||
145 | protected function addFilesystemManager( \Aimeos\MShop\Context\Item\Iface $context ) |
||
155 | |||
156 | |||
157 | /** |
||
158 | * Adds the logger object to the context |
||
159 | * |
||
160 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
161 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
162 | */ |
||
163 | protected function addLogger( \Aimeos\MShop\Context\Item\Iface $context ) |
||
170 | |||
171 | |||
172 | |||
173 | /** |
||
174 | * Adds the mailer object to the context |
||
175 | * |
||
176 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
177 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
178 | */ |
||
179 | protected function addMailer( \Aimeos\MShop\Context\Item\Iface $context ) |
||
186 | |||
187 | |||
188 | /** |
||
189 | * Adds the message queue manager object to the context |
||
190 | * |
||
191 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
192 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
193 | */ |
||
194 | protected function addMessageQueueManager( \Aimeos\MShop\Context\Item\Iface $context ) |
||
201 | |||
202 | |||
203 | /** |
||
204 | * Adds the session object to the context |
||
205 | * |
||
206 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
207 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
208 | */ |
||
209 | protected function addSession( \Aimeos\MShop\Context\Item\Iface $context ) |
||
216 | |||
217 | |||
218 | /** |
||
219 | * Adds the user ID and name if available |
||
220 | * |
||
221 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
222 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
223 | */ |
||
224 | protected function addUser( \Aimeos\MShop\Context\Item\Iface $context ) |
||
236 | |||
237 | |||
238 | /** |
||
239 | * Adds the group IDs if available |
||
240 | * |
||
241 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
242 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
243 | */ |
||
244 | protected function addGroups( \Aimeos\MShop\Context\Item\Iface $context ) |
||
257 | } |
||
258 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: