Completed
Push — master ( 4f05e2...9122ef )
by Aimeos
02:59
created
admin/jsonadm/src/Admin/JsonAdm/Base.php 1 patch
Spacing   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 * @param array $templatePaths List of file system paths where the templates are stored
34 34
 	 * @param string $path Name of the client separated by slashes, e.g "product/stock"
35 35
 	 */
36
-	public function __construct( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, array $templatePaths, $path )
36
+	public function __construct(\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, array $templatePaths, $path)
37 37
 	{
38 38
 		$this->view = $view;
39 39
 		$this->context = $context;
@@ -50,48 +50,48 @@  discard block
 block discarded – undo
50 50
 	 * @param integer &$status Variable which contains the HTTP status afterwards
51 51
 	 * @return string Content for response body
52 52
 	 */
53
-	public function delete( $body, array &$header, &$status )
53
+	public function delete($body, array &$header, &$status)
54 54
 	{
55
-		$header = array( 'Content-Type' => 'application/vnd.api+json; supported-ext="bulk"' );
55
+		$header = array('Content-Type' => 'application/vnd.api+json; supported-ext="bulk"');
56 56
 		$context = $this->getContext();
57 57
 		$view = $this->getView();
58 58
 
59 59
 		try
60 60
 		{
61
-			$view = $this->deleteItems( $view, $body );
61
+			$view = $this->deleteItems($view, $body);
62 62
 			$status = 200;
63 63
 		}
64
-		catch( \Aimeos\Admin\JsonAdm\Exception $e )
64
+		catch (\Aimeos\Admin\JsonAdm\Exception $e)
65 65
 		{
66 66
 			$status = $e->getCode();
67
-			$view->errors = array( array(
68
-				'title' => $context->getI18n()->dt( 'admin/jsonadm', $e->getMessage() ),
67
+			$view->errors = array(array(
68
+				'title' => $context->getI18n()->dt('admin/jsonadm', $e->getMessage()),
69 69
 				'detail' => $e->getTraceAsString(),
70
-			) );
70
+			));
71 71
 		}
72
-		catch( \Aimeos\MAdmin\Exception $e )
72
+		catch (\Aimeos\MAdmin\Exception $e)
73 73
 		{
74 74
 			$status = 404;
75
-			$view->errors = array( array(
76
-				'title' => $context->getI18n()->dt( 'mshop', $e->getMessage() ),
75
+			$view->errors = array(array(
76
+				'title' => $context->getI18n()->dt('mshop', $e->getMessage()),
77 77
 				'detail' => $e->getTraceAsString(),
78
-			) );
78
+			));
79 79
 		}
80
-		catch( \Aimeos\MShop\Exception $e )
80
+		catch (\Aimeos\MShop\Exception $e)
81 81
 		{
82 82
 			$status = 404;
83
-			$view->errors = array( array(
84
-				'title' => $context->getI18n()->dt( 'mshop', $e->getMessage() ),
83
+			$view->errors = array(array(
84
+				'title' => $context->getI18n()->dt('mshop', $e->getMessage()),
85 85
 				'detail' => $e->getTraceAsString(),
86
-			) );
86
+			));
87 87
 		}
88
-		catch( \Exception $e )
88
+		catch (\Exception $e)
89 89
 		{
90 90
 			$status = 500;
91
-			$view->errors = array( array(
91
+			$view->errors = array(array(
92 92
 				'title' => $e->getMessage(),
93 93
 				'detail' => $e->getTraceAsString(),
94
-			) );
94
+			));
95 95
 		}
96 96
 
97 97
 		/** admin/jsonadm/standard/template-delete
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 		$tplconf = 'admin/jsonadm/standard/template-delete';
122 122
 		$default = 'delete-default.php';
123 123
 
124
-		return $view->render( $view->config( $tplconf, $default ) );
124
+		return $view->render($view->config($tplconf, $default));
125 125
 	}
126 126
 
127 127
 
@@ -133,39 +133,39 @@  discard block
 block discarded – undo
133 133
 	 * @param integer &$status Variable which contains the HTTP status afterwards
134 134
 	 * @return string Content for response body
135 135
 	 */
136
-	public function get( $body, array &$header, &$status )
136
+	public function get($body, array &$header, &$status)
137 137
 	{
138
-		$header = array( 'Content-Type' => 'application/vnd.api+json; supported-ext="bulk"' );
138
+		$header = array('Content-Type' => 'application/vnd.api+json; supported-ext="bulk"');
139 139
 		$view = $this->getView();
140 140
 
141 141
 		try
142 142
 		{
143
-			$view = $this->getItem( $view );
143
+			$view = $this->getItem($view);
144 144
 			$status = 200;
145 145
 		}
146
-		catch( \Aimeos\MAdmin\Exception $e )
146
+		catch (\Aimeos\MAdmin\Exception $e)
147 147
 		{
148 148
 			$status = 404;
149
-			$view->errors = array( array(
150
-				'title' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ),
149
+			$view->errors = array(array(
150
+				'title' => $this->getContext()->getI18n()->dt('mshop', $e->getMessage()),
151 151
 				'detail' => $e->getTraceAsString(),
152
-			) );
152
+			));
153 153
 		}
154
-		catch( \Aimeos\MShop\Exception $e )
154
+		catch (\Aimeos\MShop\Exception $e)
155 155
 		{
156 156
 			$status = 404;
157
-			$view->errors = array( array(
158
-				'title' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ),
157
+			$view->errors = array(array(
158
+				'title' => $this->getContext()->getI18n()->dt('mshop', $e->getMessage()),
159 159
 				'detail' => $e->getTraceAsString(),
160
-			) );
160
+			));
161 161
 		}
162
-		catch( \Exception $e )
162
+		catch (\Exception $e)
163 163
 		{
164 164
 			$status = 500;
165
-			$view->errors = array( array(
165
+			$view->errors = array(array(
166 166
 				'title' => $e->getMessage(),
167 167
 				'detail' => $e->getTraceAsString(),
168
-			) );
168
+			));
169 169
 		}
170 170
 
171 171
 		/** admin/jsonadm/standard/template-get
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 		$tplconf = 'admin/jsonadm/standard/template-get';
196 196
 		$default = 'get-default.php';
197 197
 
198
-		return $view->render( $view->config( $tplconf, $default ) );
198
+		return $view->render($view->config($tplconf, $default));
199 199
 	}
200 200
 
201 201
 
@@ -207,48 +207,48 @@  discard block
 block discarded – undo
207 207
 	 * @param integer &$status Variable which contains the HTTP status afterwards
208 208
 	 * @return string Content for response body
209 209
 	 */
210
-	public function patch( $body, array &$header, &$status )
210
+	public function patch($body, array &$header, &$status)
211 211
 	{
212
-		$header = array( 'Content-Type' => 'application/vnd.api+json; supported-ext="bulk"' );
212
+		$header = array('Content-Type' => 'application/vnd.api+json; supported-ext="bulk"');
213 213
 		$context = $this->getContext();
214 214
 		$view = $this->getView();
215 215
 
216 216
 		try
217 217
 		{
218
-			$view = $this->patchItems( $view, $body, $header );
218
+			$view = $this->patchItems($view, $body, $header);
219 219
 			$status = 200;
220 220
 		}
221
-		catch( \Aimeos\Admin\JsonAdm\Exception $e )
221
+		catch (\Aimeos\Admin\JsonAdm\Exception $e)
222 222
 		{
223 223
 			$status = $e->getCode();
224
-			$view->errors = array( array(
225
-				'title' => $context->getI18n()->dt( 'admin/jsonadm', $e->getMessage() ),
224
+			$view->errors = array(array(
225
+				'title' => $context->getI18n()->dt('admin/jsonadm', $e->getMessage()),
226 226
 				'detail' => $e->getTraceAsString(),
227
-			) );
227
+			));
228 228
 		}
229
-		catch( \Aimeos\MAdmin\Exception $e )
229
+		catch (\Aimeos\MAdmin\Exception $e)
230 230
 		{
231 231
 			$status = 404;
232
-			$view->errors = array( array(
233
-				'title' => $context->getI18n()->dt( 'mshop', $e->getMessage() ),
232
+			$view->errors = array(array(
233
+				'title' => $context->getI18n()->dt('mshop', $e->getMessage()),
234 234
 				'detail' => $e->getTraceAsString(),
235
-			) );
235
+			));
236 236
 		}
237
-		catch( \Aimeos\MShop\Exception $e )
237
+		catch (\Aimeos\MShop\Exception $e)
238 238
 		{
239 239
 			$status = 404;
240
-			$view->errors = array( array(
241
-				'title' => $context->getI18n()->dt( 'mshop', $e->getMessage() ),
240
+			$view->errors = array(array(
241
+				'title' => $context->getI18n()->dt('mshop', $e->getMessage()),
242 242
 				'detail' => $e->getTraceAsString(),
243
-			) );
243
+			));
244 244
 		}
245
-		catch( \Exception $e )
245
+		catch (\Exception $e)
246 246
 		{
247 247
 			$status = 500;
248
-			$view->errors = array( array(
248
+			$view->errors = array(array(
249 249
 				'title' => $e->getMessage(),
250 250
 				'detail' => $e->getTraceAsString(),
251
-			) );
251
+			));
252 252
 		}
253 253
 
254 254
 		/** admin/jsonadm/standard/template-patch
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		$tplconf = 'admin/jsonadm/standard/template-patch';
279 279
 		$default = 'patch-default.php';
280 280
 
281
-		return $view->render( $view->config( $tplconf, $default ) );
281
+		return $view->render($view->config($tplconf, $default));
282 282
 	}
283 283
 
284 284
 
@@ -290,48 +290,48 @@  discard block
 block discarded – undo
290 290
 	 * @param integer &$status Variable which contains the HTTP status afterwards
291 291
 	 * @return string Content for response body
292 292
 	 */
293
-	public function post( $body, array &$header, &$status )
293
+	public function post($body, array &$header, &$status)
294 294
 	{
295
-		$header = array( 'Content-Type' => 'application/vnd.api+json; supported-ext="bulk"' );
295
+		$header = array('Content-Type' => 'application/vnd.api+json; supported-ext="bulk"');
296 296
 		$context = $this->getContext();
297 297
 		$view = $this->getView();
298 298
 
299 299
 		try
300 300
 		{
301
-			$view = $this->postItems( $view, $body, $header );
301
+			$view = $this->postItems($view, $body, $header);
302 302
 			$status = 201;
303 303
 		}
304
-		catch( \Aimeos\Admin\JsonAdm\Exception $e )
304
+		catch (\Aimeos\Admin\JsonAdm\Exception $e)
305 305
 		{
306 306
 			$status = $e->getCode();
307
-			$view->errors = array( array(
308
-				'title' => $context->getI18n()->dt( 'admin/jsonadm', $e->getMessage() ),
307
+			$view->errors = array(array(
308
+				'title' => $context->getI18n()->dt('admin/jsonadm', $e->getMessage()),
309 309
 				'detail' => $e->getTraceAsString(),
310
-			) );
310
+			));
311 311
 		}
312
-		catch( \Aimeos\MAdmin\Exception $e )
312
+		catch (\Aimeos\MAdmin\Exception $e)
313 313
 		{
314 314
 			$status = 404;
315
-			$view->errors = array( array(
316
-				'title' => $context->getI18n()->dt( 'mshop', $e->getMessage() ),
315
+			$view->errors = array(array(
316
+				'title' => $context->getI18n()->dt('mshop', $e->getMessage()),
317 317
 				'detail' => $e->getTraceAsString(),
318
-			) );
318
+			));
319 319
 		}
320
-		catch( \Aimeos\MShop\Exception $e )
320
+		catch (\Aimeos\MShop\Exception $e)
321 321
 		{
322 322
 			$status = 404;
323
-			$view->errors = array( array(
324
-				'title' => $context->getI18n()->dt( 'mshop', $e->getMessage() ),
323
+			$view->errors = array(array(
324
+				'title' => $context->getI18n()->dt('mshop', $e->getMessage()),
325 325
 				'detail' => $e->getTraceAsString(),
326
-			) );
326
+			));
327 327
 		}
328
-		catch( \Exception $e )
328
+		catch (\Exception $e)
329 329
 		{
330 330
 			$status = 500;
331
-			$view->errors = array( array(
331
+			$view->errors = array(array(
332 332
 				'title' => $e->getMessage(),
333 333
 				'detail' => $e->getTraceAsString(),
334
-			) );
334
+			));
335 335
 		}
336 336
 
337 337
 		/** admin/jsonadm/standard/template-post
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 		$tplconf = 'admin/jsonadm/standard/template-post';
362 362
 		$default = 'post-default.php';
363 363
 
364
-		return $view->render( $view->config( $tplconf, $default ) );
364
+		return $view->render($view->config($tplconf, $default));
365 365
 	}
366 366
 
367 367
 
@@ -373,17 +373,17 @@  discard block
 block discarded – undo
373 373
 	 * @param integer &$status Variable which contains the HTTP status afterwards
374 374
 	 * @return string Content for response body
375 375
 	 */
376
-	public function put( $body, array &$header, &$status )
376
+	public function put($body, array &$header, &$status)
377 377
 	{
378
-		$header = array( 'Content-Type' => 'application/vnd.api+json; supported-ext="bulk"' );
378
+		$header = array('Content-Type' => 'application/vnd.api+json; supported-ext="bulk"');
379 379
 		$status = 501;
380 380
 
381 381
 		$context = $this->getContext();
382 382
 		$view = $this->getView();
383 383
 
384
-		$view->errors = array( array(
385
-			'title' => $context->getI18n()->dt( 'admin/jsonadm', 'Not implemented, use PATCH instead' ),
386
-		) );
384
+		$view->errors = array(array(
385
+			'title' => $context->getI18n()->dt('admin/jsonadm', 'Not implemented, use PATCH instead'),
386
+		));
387 387
 
388 388
 		/** admin/jsonadm/standard/template-put
389 389
 		 * Relative path to the JSON API template for PUT requests
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 		$tplconf = 'admin/jsonadm/standard/template-put';
413 413
 		$default = 'put-default.php';
414 414
 
415
-		return $view->render( $view->config( $tplconf, $default ) );
415
+		return $view->render($view->config($tplconf, $default));
416 416
 	}
417 417
 
418 418
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 	 * @param integer &$status Variable which contains the HTTP status afterwards
425 425
 	 * @return string Content for response body
426 426
 	 */
427
-	public function options( $body, array &$header, &$status )
427
+	public function options($body, array &$header, &$status)
428 428
 	{
429 429
 		$context = $this->getContext();
430 430
 		$view = $this->getView();
@@ -433,11 +433,11 @@  discard block
 block discarded – undo
433 433
 		{
434 434
 			$resources = $attributes = array();
435 435
 
436
-			foreach( $this->getDomains( $view ) as $domain )
436
+			foreach ($this->getDomains($view) as $domain)
437 437
 			{
438
-				$manager = \Aimeos\MShop\Factory::createManager( $context, $domain );
439
-				$resources = array_merge( $resources, $manager->getResourceType( true ) );
440
-				$attributes = array_merge( $attributes, $manager->getSearchAttributes( true ) );
438
+				$manager = \Aimeos\MShop\Factory::createManager($context, $domain);
439
+				$resources = array_merge($resources, $manager->getResourceType(true));
440
+				$attributes = array_merge($attributes, $manager->getSearchAttributes(true));
441 441
 			}
442 442
 
443 443
 			$view->resources = $resources;
@@ -449,29 +449,29 @@  discard block
 block discarded – undo
449 449
 			);
450 450
 			$status = 200;
451 451
 		}
452
-		catch( \Aimeos\MAdmin\Exception $e )
452
+		catch (\Aimeos\MAdmin\Exception $e)
453 453
 		{
454 454
 			$status = 404;
455
-			$view->errors = array( array(
456
-				'title' => $context->getI18n()->dt( 'mshop', $e->getMessage() ),
455
+			$view->errors = array(array(
456
+				'title' => $context->getI18n()->dt('mshop', $e->getMessage()),
457 457
 				'detail' => $e->getTraceAsString(),
458
-			) );
458
+			));
459 459
 		}
460
-		catch( \Aimeos\MShop\Exception $e )
460
+		catch (\Aimeos\MShop\Exception $e)
461 461
 		{
462 462
 			$status = 404;
463
-			$view->errors = array( array(
464
-				'title' => $context->getI18n()->dt( 'mshop', $e->getMessage() ),
463
+			$view->errors = array(array(
464
+				'title' => $context->getI18n()->dt('mshop', $e->getMessage()),
465 465
 				'detail' => $e->getTraceAsString(),
466
-			) );
466
+			));
467 467
 		}
468
-		catch( \Exception $e )
468
+		catch (\Exception $e)
469 469
 		{
470 470
 			$status = 500;
471
-			$view->errors = array( array(
471
+			$view->errors = array(array(
472 472
 				'title' => $e->getMessage(),
473 473
 				'detail' => $e->getTraceAsString(),
474
-			) );
474
+			));
475 475
 		}
476 476
 
477 477
 		/** admin/jsonadm/standard/template-options
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
 		$tplconf = 'admin/jsonadm/standard/template-options';
502 502
 		$default = 'options-default.php';
503 503
 
504
-		return $view->render( $view->config( $tplconf, $default ) );
504
+		return $view->render($view->config($tplconf, $default));
505 505
 	}
506 506
 
507 507
 
@@ -513,23 +513,23 @@  discard block
 block discarded – undo
513 513
 	 * @return \Aimeos\MW\View\Iface $view View object that will contain the "total" property afterwards
514 514
 	 * @throws \Aimeos\Admin\JsonAdm\Exception If the request body is invalid
515 515
 	 */
516
-	protected function deleteItems( \Aimeos\MW\View\Iface $view, $body )
516
+	protected function deleteItems(\Aimeos\MW\View\Iface $view, $body)
517 517
 	{
518
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $this->getPath() );
518
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $this->getPath());
519 519
 
520
-		if( ( $id = $view->param( 'id' ) ) == null )
520
+		if (($id = $view->param('id')) == null)
521 521
 		{
522
-			if( ( $request = json_decode( $body ) ) === null || !isset( $request->data ) || !is_array( $request->data ) ) {
523
-				throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid JSON in body' ), 400 );
522
+			if (($request = json_decode($body)) === null || !isset($request->data) || !is_array($request->data)) {
523
+				throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Invalid JSON in body'), 400);
524 524
 			}
525 525
 
526
-			$ids = $this->getIds( $request );
527
-			$manager->deleteItems( $ids );
528
-			$view->total = count( $ids );
526
+			$ids = $this->getIds($request);
527
+			$manager->deleteItems($ids);
528
+			$view->total = count($ids);
529 529
 		}
530 530
 		else
531 531
 		{
532
-			$manager->deleteItem( $id );
532
+			$manager->deleteItem($id);
533 533
 			$view->total = 1;
534 534
 		}
535 535
 
@@ -543,27 +543,27 @@  discard block
 block discarded – undo
543 543
 	 * @param \Aimeos\MW\View\Iface $view View instance
544 544
 	 * @return \Aimeos\MW\View\Iface View instance with additional data assigned
545 545
 	 */
546
-	protected function getItem( \Aimeos\MW\View\Iface $view )
546
+	protected function getItem(\Aimeos\MW\View\Iface $view)
547 547
 	{
548 548
 		$total = 1;
549
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $this->getPath() );
550
-		$include = ( ( $include = $view->param( 'include' ) ) !== null ? explode( ',', $include ) : array() );
549
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $this->getPath());
550
+		$include = (($include = $view->param('include')) !== null ? explode(',', $include) : array());
551 551
 
552
-		if( ( $id = $view->param( 'id' ) ) == null )
552
+		if (($id = $view->param('id')) == null)
553 553
 		{
554
-			$search = $this->initCriteria( $manager->createSearch(), $view->param() );
555
-			$view->data = $manager->searchItems( $search, array(), $total );
556
-			$view->childItems = $this->getChildItems( $view->data, $include );
557
-			$view->listItems = $this->getListItems( $view->data, $include );
554
+			$search = $this->initCriteria($manager->createSearch(), $view->param());
555
+			$view->data = $manager->searchItems($search, array(), $total);
556
+			$view->childItems = $this->getChildItems($view->data, $include);
557
+			$view->listItems = $this->getListItems($view->data, $include);
558 558
 		}
559 559
 		else
560 560
 		{
561
-			$view->data = $manager->getItem( $id, array() );
562
-			$view->childItems = $this->getChildItems( array( $id => $view->data ), $include );
563
-			$view->listItems = $this->getListItems( array( $id => $view->data ), $include );
561
+			$view->data = $manager->getItem($id, array());
562
+			$view->childItems = $this->getChildItems(array($id => $view->data), $include);
563
+			$view->listItems = $this->getListItems(array($id => $view->data), $include);
564 564
 		}
565 565
 
566
-		$view->refItems = $this->getRefItems( $view->listItems );
566
+		$view->refItems = $this->getRefItems($view->listItems);
567 567
 
568 568
 		$view->total = $total;
569 569
 
@@ -588,11 +588,11 @@  discard block
 block discarded – undo
588 588
 	 * @param array $params List of criteria data with condition, sorting and paging
589 589
 	 * @return \Aimeos\MW\Criteria\Iface Initialized criteria object
590 590
 	 */
591
-	protected function initCriteria( \Aimeos\MW\Criteria\Iface $criteria, array $params )
591
+	protected function initCriteria(\Aimeos\MW\Criteria\Iface $criteria, array $params)
592 592
 	{
593
-		$this->initCriteriaConditions( $criteria, $params );
594
-		$this->initCriteriaSortations( $criteria, $params );
595
-		$this->initCriteriaSlice( $criteria, $params );
593
+		$this->initCriteriaConditions($criteria, $params);
594
+		$this->initCriteriaSortations($criteria, $params);
595
+		$this->initCriteriaSlice($criteria, $params);
596 596
 
597 597
 		return $criteria;
598 598
 	}
@@ -604,15 +604,15 @@  discard block
 block discarded – undo
604 604
 	 * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object
605 605
 	 * @param array $params List of criteria data with condition, sorting and paging
606 606
 	 */
607
-	private function initCriteriaConditions( \Aimeos\MW\Criteria\Iface $criteria, array $params )
607
+	private function initCriteriaConditions(\Aimeos\MW\Criteria\Iface $criteria, array $params)
608 608
 	{
609
-		if( isset( $params['filter'] ) && is_array( $params['filter'] ) )
609
+		if (isset($params['filter']) && is_array($params['filter']))
610 610
 		{
611 611
 			$existing = $criteria->getConditions();
612
-			$criteria->setConditions( $criteria->toConditions( (array) $params['filter'] ) );
612
+			$criteria->setConditions($criteria->toConditions((array) $params['filter']));
613 613
 
614
-			$expr = array( $criteria->getConditions(), $existing );
615
-			$criteria->setConditions( $criteria->combine( '&&', $expr ) );
614
+			$expr = array($criteria->getConditions(), $existing);
615
+			$criteria->setConditions($criteria->combine('&&', $expr));
616 616
 		}
617 617
 	}
618 618
 
@@ -623,12 +623,12 @@  discard block
 block discarded – undo
623 623
 	 * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object
624 624
 	 * @param array $params List of criteria data with condition, sorting and paging
625 625
 	 */
626
-	private function initCriteriaSlice( \Aimeos\MW\Criteria\Iface $criteria, array $params )
626
+	private function initCriteriaSlice(\Aimeos\MW\Criteria\Iface $criteria, array $params)
627 627
 	{
628
-		$start = ( isset( $params['page']['offset'] ) ? $params['page']['offset'] : 0 );
629
-		$size = ( isset( $params['page']['limit'] ) ? $params['page']['limit'] : 25 );
628
+		$start = (isset($params['page']['offset']) ? $params['page']['offset'] : 0);
629
+		$size = (isset($params['page']['limit']) ? $params['page']['limit'] : 25);
630 630
 
631
-		$criteria->setSlice( $start, $size );
631
+		$criteria->setSlice($start, $size);
632 632
 	}
633 633
 
634 634
 
@@ -638,24 +638,24 @@  discard block
 block discarded – undo
638 638
 	 * @param \Aimeos\MW\Criteria\Iface $criteria Criteria object
639 639
 	 * @param array $params List of criteria data with condition, sorting and paging
640 640
 	 */
641
-	private function initCriteriaSortations( \Aimeos\MW\Criteria\Iface $criteria, array $params )
641
+	private function initCriteriaSortations(\Aimeos\MW\Criteria\Iface $criteria, array $params)
642 642
 	{
643
-		if( !isset( $params['sort'] ) ) {
643
+		if (!isset($params['sort'])) {
644 644
 			return;
645 645
 		}
646 646
 
647 647
 		$sortation = array();
648 648
 
649
-		foreach( explode( ',', $params['sort'] ) as $sort )
649
+		foreach (explode(',', $params['sort']) as $sort)
650 650
 		{
651
-			if( $sort[0] === '-' ) {
652
-				$sortation[] = $criteria->sort( '-', substr( $sort, 1 ) );
651
+			if ($sort[0] === '-') {
652
+				$sortation[] = $criteria->sort('-', substr($sort, 1));
653 653
 			} else {
654
-				$sortation[] = $criteria->sort( '+', $sort ); break;
654
+				$sortation[] = $criteria->sort('+', $sort); break;
655 655
 			}
656 656
 		}
657 657
 
658
-		$criteria->setSortations( $sortation );
658
+		$criteria->setSortations($sortation);
659 659
 	}
660 660
 
661 661
 
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
 	 * @param \Aimeos\MW\View\Iface $view View object with "resource" parameter
666 666
 	 * @return array List of domain names
667 667
 	 */
668
-	protected function getDomains( \Aimeos\MW\View\Iface $view )
668
+	protected function getDomains(\Aimeos\MW\View\Iface $view)
669 669
 	{
670
-		if( ( $domains = $view->param( 'resource' ) ) == '' )
670
+		if (($domains = $view->param('resource')) == '')
671 671
 		{
672 672
 			/** admin/jsonadm/domains
673 673
 			 * A list of domain names whose clients are available for the JSON API
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 				'attribute', 'catalog', 'coupon', 'customer', 'locale', 'media',
690 690
 				'order', 'plugin', 'price', 'product', 'service', 'supplier', 'tag', 'text'
691 691
 			);
692
-			$domains = $this->getContext()->getConfig()->get( 'admin/jsonadm/domains', $default );
692
+			$domains = $this->getContext()->getConfig()->get('admin/jsonadm/domains', $default);
693 693
 		}
694 694
 
695 695
 		return (array) $domains;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 	 * @param array $include List of resource types that should be fetched
704 704
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Iface
705 705
 	 */
706
-	protected function getChildItems( array $items, array $include )
706
+	protected function getChildItems(array $items, array $include)
707 707
 	{
708 708
 		return array();
709 709
 	}
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 	 * @param array $include List of resource types that should be fetched
717 717
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Lists\Iface
718 718
 	 */
719
-	protected function getListItems( array $items, array $include )
719
+	protected function getListItems(array $items, array $include)
720 720
 	{
721 721
 		return array();
722 722
 	}
@@ -728,22 +728,22 @@  discard block
 block discarded – undo
728 728
 	 * @param array $listItems List of items implementing \Aimeos\MShop\Common\Item\Lists\Iface
729 729
 	 * @return array List of items implementing \Aimeos\MShop\Common\Item\Iface
730 730
 	 */
731
-	protected function getRefItems( array $listItems )
731
+	protected function getRefItems(array $listItems)
732 732
 	{
733 733
 		$list = $map = array();
734 734
 
735
-		foreach( $listItems as $listItem ) {
735
+		foreach ($listItems as $listItem) {
736 736
 			$map[$listItem->getDomain()][] = $listItem->getRefId();
737 737
 		}
738 738
 
739
-		foreach( $map as $domain => $ids )
739
+		foreach ($map as $domain => $ids)
740 740
 		{
741
-			$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $domain );
741
+			$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $domain);
742 742
 
743 743
 			$search = $manager->createSearch();
744
-			$search->setConditions( $search->compare( '==', $domain . '.id', $ids ) );
744
+			$search->setConditions($search->compare('==', $domain . '.id', $ids));
745 745
 
746
-			$list = array_merge( $list, $manager->searchItems( $search ) );
746
+			$list = array_merge($list, $manager->searchItems($search));
747 747
 		}
748 748
 
749 749
 		return $list;
@@ -756,15 +756,15 @@  discard block
 block discarded – undo
756 756
 	 * @param \stdClass $request Decoded request body
757 757
 	 * @return array List of item IDs
758 758
 	 */
759
-	protected function getIds( $request )
759
+	protected function getIds($request)
760 760
 	{
761 761
 		$ids = array();
762 762
 
763
-		if( isset( $request->data ) )
763
+		if (isset($request->data))
764 764
 		{
765
-			foreach( $request->data as $entry )
765
+			foreach ($request->data as $entry)
766 766
 			{
767
-				if( isset( $entry->id ) ) {
767
+				if (isset($entry->id)) {
768 768
 					$ids[] = $entry->id;
769 769
 				}
770 770
 			}
@@ -816,30 +816,30 @@  discard block
 block discarded – undo
816 816
 	 * @throws \Aimeos\Admin\JsonAdm\Exception If "id" parameter isn't available or the body is invalid
817 817
 	 * @return \Aimeos\MW\View\Iface Updated view instance
818 818
 	 */
819
-	protected function patchItems( \Aimeos\MW\View\Iface $view, $body, array &$header )
819
+	protected function patchItems(\Aimeos\MW\View\Iface $view, $body, array &$header)
820 820
 	{
821
-		if( ( $request = json_decode( $body ) ) === null || !isset( $request->data ) ) {
822
-			throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid JSON in body' ), 400 );
821
+		if (($request = json_decode($body)) === null || !isset($request->data)) {
822
+			throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Invalid JSON in body'), 400);
823 823
 		}
824 824
 
825
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $this->getPath() );
825
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $this->getPath());
826 826
 
827
-		if( is_array( $request->data ) )
827
+		if (is_array($request->data))
828 828
 		{
829
-			$data = $this->saveData( $manager, $request );
829
+			$data = $this->saveData($manager, $request);
830 830
 
831 831
 			$view->data = $data;
832
-			$view->total = count( $data );
832
+			$view->total = count($data);
833 833
 			$header['Content-Type'] = 'application/vnd.api+json; ext="bulk"; supported-ext="bulk"';
834 834
 		}
835 835
 		else
836 836
 		{
837
-			if( ( $id = $view->param( 'id' ) ) == null ) {
838
-				throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'No ID given' ), 400 );
837
+			if (($id = $view->param('id')) == null) {
838
+				throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('No ID given'), 400);
839 839
 			}
840 840
 
841 841
 			$request->data->id = $id;
842
-			$data = $this->saveEntry( $manager, $request->data );
842
+			$data = $this->saveEntry($manager, $request->data);
843 843
 
844 844
 			$view->data = $data;
845 845
 			$view->total = 1;
@@ -857,31 +857,31 @@  discard block
 block discarded – undo
857 857
 	 * @param array &$header Associative list of HTTP headers as value/result parameter
858 858
 	 * @return \Aimeos\MW\View\Iface Updated view instance
859 859
 	 */
860
-	protected function postItems( \Aimeos\MW\View\Iface $view, $body, array &$header )
860
+	protected function postItems(\Aimeos\MW\View\Iface $view, $body, array &$header)
861 861
 	{
862
-		if( ( $request = json_decode( $body ) ) === null || !isset( $request->data ) ) {
863
-			throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Invalid JSON in body' ), 400 );
862
+		if (($request = json_decode($body)) === null || !isset($request->data)) {
863
+			throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Invalid JSON in body'), 400);
864 864
 		}
865 865
 
866
-		if( isset( $request->data->id ) || $view->param( 'id' ) != null ) {
867
-			throw new \Aimeos\Admin\JsonAdm\Exception( sprintf( 'Client generated IDs are not supported' ), 403 );
866
+		if (isset($request->data->id) || $view->param('id') != null) {
867
+			throw new \Aimeos\Admin\JsonAdm\Exception(sprintf('Client generated IDs are not supported'), 403);
868 868
 		}
869 869
 
870 870
 
871
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), $this->getPath() );
871
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), $this->getPath());
872 872
 
873
-		if( is_array( $request->data ) )
873
+		if (is_array($request->data))
874 874
 		{
875
-			$data = $this->saveData( $manager, $request );
875
+			$data = $this->saveData($manager, $request);
876 876
 
877 877
 			$view->data = $data;
878
-			$view->total = count( $data );
878
+			$view->total = count($data);
879 879
 			$header['Content-Type'] = 'application/vnd.api+json; ext="bulk"; supported-ext="bulk"';
880 880
 		}
881 881
 		else
882 882
 		{
883 883
 			$request->data->id = null;
884
-			$data = $this->saveEntry( $manager, $request->data );
884
+			$data = $this->saveEntry($manager, $request->data);
885 885
 
886 886
 			$view->data = $data;
887 887
 			$view->total = 1;
@@ -898,14 +898,14 @@  discard block
 block discarded – undo
898 898
 	 * @param \stdClass $request Object with request body data
899 899
 	 * @return array List of items
900 900
 	 */
901
-	protected function saveData( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $request )
901
+	protected function saveData(\Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $request)
902 902
 	{
903 903
 		$data = array();
904 904
 
905
-		if( isset( $request->data ) )
905
+		if (isset($request->data))
906 906
 		{
907
-			foreach( (array) $request->data as $entry ) {
908
-				$data[] = $this->saveEntry( $manager, $entry );
907
+			foreach ((array) $request->data as $entry) {
908
+				$data[] = $this->saveEntry($manager, $entry);
909 909
 			}
910 910
 		}
911 911
 
@@ -920,19 +920,19 @@  discard block
 block discarded – undo
920 920
 	 * @param \stdClass $entry Object including "id" and "attributes" elements
921 921
 	 * @return \Aimeos\MShop\Common\Item\Iface New or updated item
922 922
 	 */
923
-	protected function saveEntry( \Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry )
923
+	protected function saveEntry(\Aimeos\MShop\Common\Manager\Iface $manager, \stdClass $entry)
924 924
 	{
925
-		$attr = ( isset( $entry->attributes ) ? (array) $entry->attributes : array() );
925
+		$attr = (isset($entry->attributes) ? (array) $entry->attributes : array());
926 926
 
927
-		if( isset( $entry->id ) && $entry->id !== null ) {
928
-			$item = $manager->getItem( $entry->id );
927
+		if (isset($entry->id) && $entry->id !== null) {
928
+			$item = $manager->getItem($entry->id);
929 929
 		} else {
930 930
 			$item = $manager->createItem();
931 931
 		}
932 932
 
933
-		$item->fromArray( $attr );
934
-		$manager->saveItem( $item );
933
+		$item->fromArray($attr);
934
+		$manager->saveItem($item);
935 935
 
936
-		return $manager->getItem( $item->getId() );
936
+		return $manager->getItem($item->getId());
937 937
 	}
938 938
 }
Please login to merge, or discard this patch.