Completed
Push — master ( e3ddba...ecd828 )
by Aimeos
02:57
created
Service/View.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -276,7 +276,6 @@
 block discarded – undo
276 276
 	/**
277 277
 	 * Adds the Aimeos template functions for Twig
278 278
 	 *
279
-	 * @param \Twig_Environment $env Twig environment object
280 279
 	 * @param \Aimeos\MW\View\Iface $view View object
281 280
 	 */
282 281
 	protected function initTwig( \Aimeos\MW\View\Iface $view, \Twig_Environment $twig )
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * @param RequestStack $requestStack Current request stack
33 33
 	 * @param Container $container Container object to access parameters
34 34
 	 */
35
-	public function __construct( RequestStack $requestStack, Container $container )
35
+	public function __construct(RequestStack $requestStack, Container $container)
36 36
 	{
37 37
 		$this->requestStack = $requestStack;
38 38
 		$this->container = $container;
@@ -47,24 +47,24 @@  discard block
 block discarded – undo
47 47
 	 * @param string|null $locale Code of the current language or null for no translation
48 48
 	 * @return \Aimeos\MW\View\Iface View object
49 49
 	 */
50
-	public function create( \Aimeos\MShop\Context\Item\Iface $context, array $templatePaths, $locale = null )
50
+	public function create(\Aimeos\MShop\Context\Item\Iface $context, array $templatePaths, $locale = null)
51 51
 	{
52 52
 		$config = $context->getConfig();
53
-		$twig = $this->container->get( 'twig' );
54
-		$engine = new \Aimeos\MW\View\Engine\Twig( $twig );
55
-		$view = new \Aimeos\MW\View\Standard( $templatePaths, array( '.html.twig' => $engine ) );
56
-
57
-		$this->addCsrf( $view );
58
-		$this->addAccess( $view, $context );
59
-		$this->addConfig( $view, $config );
60
-		$this->addNumber( $view, $config );
61
-		$this->addParam( $view );
62
-		$this->addRequest( $view );
63
-		$this->addResponse( $view );
64
-		$this->addTranslate( $view, $locale );
65
-		$this->addUrl( $view );
66
-
67
-		$this->initTwig( $view, $twig );
53
+		$twig = $this->container->get('twig');
54
+		$engine = new \Aimeos\MW\View\Engine\Twig($twig);
55
+		$view = new \Aimeos\MW\View\Standard($templatePaths, array('.html.twig' => $engine));
56
+
57
+		$this->addCsrf($view);
58
+		$this->addAccess($view, $context);
59
+		$this->addConfig($view, $config);
60
+		$this->addNumber($view, $config);
61
+		$this->addParam($view);
62
+		$this->addRequest($view);
63
+		$this->addResponse($view);
64
+		$this->addTranslate($view, $locale);
65
+		$this->addUrl($view);
66
+
67
+		$this->initTwig($view, $twig);
68 68
 
69 69
 		return $view;
70 70
 	}
@@ -77,26 +77,26 @@  discard block
 block discarded – undo
77 77
 	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
78 78
 	 * @return \Aimeos\MW\View\Iface Modified view object
79 79
 	 */
80
-	protected function addAccess( \Aimeos\MW\View\Iface $view, \Aimeos\MShop\Context\Item\Iface $context )
80
+	protected function addAccess(\Aimeos\MW\View\Iface $view, \Aimeos\MShop\Context\Item\Iface $context)
81 81
 	{
82 82
 		$container = $this->container;
83
-		$token = $this->container->get( 'security.token_storage' )->getToken();
83
+		$token = $this->container->get('security.token_storage')->getToken();
84 84
 
85
-		if( is_object( $token ) && is_object( $token->getUser() )
86
-			&& in_array( 'ROLE_ADMIN', (array) $token->getUser()->getRoles() ) )
85
+		if (is_object($token) && is_object($token->getUser())
86
+			&& in_array('ROLE_ADMIN', (array) $token->getUser()->getRoles()))
87 87
 		{
88
-			$helper = new \Aimeos\MW\View\Helper\Access\All( $view );
88
+			$helper = new \Aimeos\MW\View\Helper\Access\All($view);
89 89
 		}
90 90
 		else
91 91
 		{
92
-			$fcn = function() use ( $container, $context ) {
93
-				return $container->get( 'aimeos_support' )->getGroups( $context );
92
+			$fcn = function() use ($container, $context) {
93
+				return $container->get('aimeos_support')->getGroups($context);
94 94
 			};
95 95
 
96
-			$helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, $fcn );
96
+			$helper = new \Aimeos\MW\View\Helper\Access\Standard($view, $fcn);
97 97
 		}
98 98
 
99
-		$view->addHelper( 'access', $helper );
99
+		$view->addHelper('access', $helper);
100 100
 
101 101
 		return $view;
102 102
 	}
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
109 109
 	 * @param \Aimeos\MW\Config\Iface $config Configuration object
110 110
 	 * @return \Aimeos\MW\View\Iface Modified view object
111 111
 	 */
112
-	protected function addConfig( \Aimeos\MW\View\Iface $view, \Aimeos\MW\Config\Iface $config )
112
+	protected function addConfig(\Aimeos\MW\View\Iface $view, \Aimeos\MW\Config\Iface $config)
113 113
 	{
114
-		$config = new \Aimeos\MW\Config\Decorator\Protect( clone $config, array( 'admin', 'client' ) );
115
-		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
116
-		$view->addHelper( 'config', $helper );
114
+		$config = new \Aimeos\MW\Config\Decorator\Protect(clone $config, array('admin', 'client'));
115
+		$helper = new \Aimeos\MW\View\Helper\Config\Standard($view, $config);
116
+		$view->addHelper('config', $helper);
117 117
 
118 118
 		return $view;
119 119
 	}
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
 	 * @param \Aimeos\MW\View\Iface $view View object
126 126
 	 * @return \Aimeos\MW\View\Iface Modified view object
127 127
 	 */
128
-	protected function addCsrf( \Aimeos\MW\View\Iface $view )
128
+	protected function addCsrf(\Aimeos\MW\View\Iface $view)
129 129
 	{
130
-		$token = $this->container->get( 'security.csrf.token_manager' )->getToken( '_token' );
131
-		$helper = new \Aimeos\MW\View\Helper\Csrf\Standard( $view, '_token', $token->getValue() );
132
-		$view->addHelper( 'csrf', $helper );
130
+		$token = $this->container->get('security.csrf.token_manager')->getToken('_token');
131
+		$helper = new \Aimeos\MW\View\Helper\Csrf\Standard($view, '_token', $token->getValue());
132
+		$view->addHelper('csrf', $helper);
133 133
 
134 134
 		return $view;
135 135
 	}
@@ -142,14 +142,14 @@  discard block
 block discarded – undo
142 142
 	 * @param \Aimeos\MW\Config\Iface $config Configuration object
143 143
 	 * @return \Aimeos\MW\View\Iface Modified view object
144 144
 	 */
145
-	protected function addNumber( \Aimeos\MW\View\Iface $view, \Aimeos\MW\Config\Iface $config )
145
+	protected function addNumber(\Aimeos\MW\View\Iface $view, \Aimeos\MW\Config\Iface $config)
146 146
 	{
147
-		$sepDec = $config->get( 'client/html/common/format/separatorDecimal', '.' );
148
-		$sep1000 = $config->get( 'client/html/common/format/separator1000', ' ' );
149
-		$decimals = $config->get( 'client/html/common/format/decimals', 2 );
147
+		$sepDec = $config->get('client/html/common/format/separatorDecimal', '.');
148
+		$sep1000 = $config->get('client/html/common/format/separator1000', ' ');
149
+		$decimals = $config->get('client/html/common/format/decimals', 2);
150 150
 
151
-		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, $sepDec, $sep1000, $decimals );
152
-		$view->addHelper( 'number', $helper );
151
+		$helper = new \Aimeos\MW\View\Helper\Number\Standard($view, $sepDec, $sep1000, $decimals);
152
+		$view->addHelper('number', $helper);
153 153
 
154 154
 		return $view;
155 155
 	}
@@ -161,17 +161,17 @@  discard block
 block discarded – undo
161 161
 	 * @param \Aimeos\MW\View\Iface $view View object
162 162
 	 * @return \Aimeos\MW\View\Iface Modified view object
163 163
 	 */
164
-	protected function addParam( \Aimeos\MW\View\Iface $view )
164
+	protected function addParam(\Aimeos\MW\View\Iface $view)
165 165
 	{
166 166
 		$params = array();
167 167
 		$request = $this->requestStack->getMasterRequest();
168 168
 
169
-		if( $request !== null ) {
170
-			$params = $request->request->all() + $request->query->all() + $request->attributes->get( '_route_params' );
169
+		if ($request !== null) {
170
+			$params = $request->request->all() + $request->query->all() + $request->attributes->get('_route_params');
171 171
 		}
172 172
 
173
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $params );
174
-		$view->addHelper( 'param', $helper );
173
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($view, $params);
174
+		$view->addHelper('param', $helper);
175 175
 
176 176
 		return $view;
177 177
 	}
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
 	 * @param \Aimeos\MW\View\Iface $view View object
184 184
 	 * @return \Aimeos\MW\View\Iface Modified view object
185 185
 	 */
186
-	protected function addRequest( \Aimeos\MW\View\Iface $view )
186
+	protected function addRequest(\Aimeos\MW\View\Iface $view)
187 187
 	{
188 188
 		$request = $this->requestStack->getMasterRequest();
189 189
 
190
-		if( $request !== null )
190
+		if ($request !== null)
191 191
 		{
192
-			$helper = new \Aimeos\MW\View\Helper\Request\Symfony2( $view, $request );
193
-			$view->addHelper( 'request', $helper );
192
+			$helper = new \Aimeos\MW\View\Helper\Request\Symfony2($view, $request);
193
+			$view->addHelper('request', $helper);
194 194
 		}
195 195
 
196 196
 		return $view;
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
 	 * @param \Aimeos\MW\View\Iface $view View object
204 204
 	 * @return \Aimeos\MW\View\Iface Modified view object
205 205
 	 */
206
-	protected function addResponse( \Aimeos\MW\View\Iface $view )
206
+	protected function addResponse(\Aimeos\MW\View\Iface $view)
207 207
 	{
208
-		$helper = new \Aimeos\MW\View\Helper\Response\Symfony2( $view );
209
-		$view->addHelper( 'response', $helper );
208
+		$helper = new \Aimeos\MW\View\Helper\Response\Symfony2($view);
209
+		$view->addHelper('response', $helper);
210 210
 
211 211
 		return $view;
212 212
 	}
@@ -219,20 +219,20 @@  discard block
 block discarded – undo
219 219
 	 * @param string|null $locale ISO language code, e.g. "de" or "de_CH"
220 220
 	 * @return \Aimeos\MW\View\Iface Modified view object
221 221
 	 */
222
-	protected function addTranslate( \Aimeos\MW\View\Iface $view, $locale )
222
+	protected function addTranslate(\Aimeos\MW\View\Iface $view, $locale)
223 223
 	{
224
-		if( $locale !== null )
224
+		if ($locale !== null)
225 225
 		{
226
-			$i18n = $this->container->get( 'aimeos_i18n' )->get( array( $locale ) );
226
+			$i18n = $this->container->get('aimeos_i18n')->get(array($locale));
227 227
 			$translation = $i18n[$locale];
228 228
 		}
229 229
 		else
230 230
 		{
231
-			$translation = new \Aimeos\MW\Translation\None( 'en' );
231
+			$translation = new \Aimeos\MW\Translation\None('en');
232 232
 		}
233 233
 
234
-		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $translation );
235
-		$view->addHelper( 'translate', $helper );
234
+		$helper = new \Aimeos\MW\View\Helper\Translate\Standard($view, $translation);
235
+		$view->addHelper('translate', $helper);
236 236
 
237 237
 		return $view;
238 238
 	}
@@ -244,30 +244,30 @@  discard block
 block discarded – undo
244 244
 	 * @param \Aimeos\MW\View\Iface $view View object
245 245
 	 * @return \Aimeos\MW\View\Iface Modified view object
246 246
 	 */
247
-	protected function addUrl( \Aimeos\MW\View\Iface $view )
247
+	protected function addUrl(\Aimeos\MW\View\Iface $view)
248 248
 	{
249 249
 		$fixed = array();
250 250
 		$request = $this->requestStack->getMasterRequest();
251 251
 
252
-		if( $request !== null )
252
+		if ($request !== null)
253 253
 		{
254 254
 			$attr = $request->attributes;
255 255
 
256
-			if( ( $site = $attr->get( 'site' ) ) !== null ) {
256
+			if (($site = $attr->get('site')) !== null) {
257 257
 				$fixed['site'] = $site;
258 258
 			}
259 259
 
260
-			if( ( $lang = $attr->get( 'locale' ) ) !== null ) {
260
+			if (($lang = $attr->get('locale')) !== null) {
261 261
 				$fixed['locale'] = $lang;
262 262
 			}
263 263
 
264
-			if( ( $currency = $attr->get( 'currency' ) ) !== null ) {
264
+			if (($currency = $attr->get('currency')) !== null) {
265 265
 				$fixed['currency'] = $currency;
266 266
 			}
267 267
 		}
268 268
 
269
-		$helper = new \Aimeos\MW\View\Helper\Url\Symfony2( $view, $this->container->get( 'router' ), $fixed );
270
-		$view->addHelper( 'url', $helper );
269
+		$helper = new \Aimeos\MW\View\Helper\Url\Symfony2($view, $this->container->get('router'), $fixed);
270
+		$view->addHelper('url', $helper);
271 271
 
272 272
 		return $view;
273 273
 	}
@@ -279,21 +279,21 @@  discard block
 block discarded – undo
279 279
 	 * @param \Twig_Environment $env Twig environment object
280 280
 	 * @param \Aimeos\MW\View\Iface $view View object
281 281
 	 */
282
-	protected function initTwig( \Aimeos\MW\View\Iface $view, \Twig_Environment $twig )
282
+	protected function initTwig(\Aimeos\MW\View\Iface $view, \Twig_Environment $twig)
283 283
 	{
284
-		$fcn = function( $key, $default = null ) use ( $view ) {
285
-			return $view->config( $key, $default );
284
+		$fcn = function($key, $default = null) use ($view) {
285
+			return $view->config($key, $default);
286 286
 		};
287
-		$twig->addFunction( new \Twig_SimpleFunction( 'aiconfig', $fcn ) );
287
+		$twig->addFunction(new \Twig_SimpleFunction('aiconfig', $fcn));
288 288
 
289
-		$fcn = function( $singular, array $values = array(), $domain = 'client' ) use ( $view ) {
290
-			return vsprintf( $view->translate( $domain, $singular ), $values );
289
+		$fcn = function($singular, array $values = array(), $domain = 'client') use ($view) {
290
+			return vsprintf($view->translate($domain, $singular), $values);
291 291
 		};
292
-		$twig->addFunction( new \Twig_SimpleFunction( 'aitrans', $fcn ) );
292
+		$twig->addFunction(new \Twig_SimpleFunction('aitrans', $fcn));
293 293
 
294
-		$fcn = function( $singular, $plural, $number, array $values = array(), $domain = 'client' ) use ( $view ) {
295
-			return vsprintf( $view->translate( $domain, $singular, $plural, $number ), $values );
294
+		$fcn = function($singular, $plural, $number, array $values = array(), $domain = 'client') use ($view) {
295
+			return vsprintf($view->translate($domain, $singular, $plural, $number), $values);
296 296
 		};
297
-		$twig->addFunction( new \Twig_SimpleFunction( 'aitransplural', $fcn ) );
297
+		$twig->addFunction(new \Twig_SimpleFunction('aitransplural', $fcn));
298 298
 	}
299 299
 }
Please login to merge, or discard this patch.