Skip to content

Commit 74a6f2d

Browse files
authored
Optimize Code
When calling `create()` outside of the `processPostData()` method (analog to `processBodyContent`) we can override the method to change the behaviour of parsing POST-Params and also getting the result back and not the response of the action. All other cases `GET`, `PUT`, `PATCH` and `DELETE` also calls their similar method in directly in the `onDispatch()` method. These changes doesn't infect the workflow. It's just a small code optimization.
1 parent 9510e9f commit 74a6f2d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Controller/AbstractRestfulController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ public function onDispatch(MvcEvent $e)
425425
// POST
426426
case 'post':
427427
$action = 'create';
428-
$return = $this->processPostData($request);
428+
$data = $this->processPostData($request);
429+
$return = $this->create($data);
429430
break;
430431
// PUT
431432
case 'put':
@@ -454,7 +455,7 @@ public function onDispatch(MvcEvent $e)
454455
}
455456

456457
/**
457-
* Process post data and call create
458+
* Process post data
458459
*
459460
* @param Request $request
460461
* @return mixed
@@ -464,10 +465,10 @@ public function onDispatch(MvcEvent $e)
464465
public function processPostData(Request $request)
465466
{
466467
if ($this->requestHasContentType($request, self::CONTENT_TYPE_JSON)) {
467-
return $this->create($this->jsonDecode($request->getContent()));
468+
return $this->jsonDecode($request->getContent());
468469
}
469470

470-
return $this->create($request->getPost()->toArray());
471+
return $request->getPost()->toArray();
471472
}
472473

473474
/**

0 commit comments

Comments
 (0)