Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 7d33ff7

Browse files
committed
Splitting request checks into their own method
1 parent e4824a3 commit 7d33ff7

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/Controller/MiddlewareController.php

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,14 @@ public function __construct(
5757

5858
/**
5959
* {@inheritDoc}
60-
* @throws \Zend\Mvc\Exception\RuntimeException
60+
*
61+
* @throws RuntimeException
6162
*/
6263
public function onDispatch(MvcEvent $e)
6364
{
64-
$request = $this->request;
65-
$response = $this->response;
66-
67-
if (! $request instanceof Request) {
68-
throw new RuntimeException(sprintf(
69-
'Expected request to be a %s, %s given',
70-
Request::class,
71-
get_class($request)
72-
));
73-
}
74-
75-
if (! $response instanceof Response) {
76-
throw new RuntimeException(sprintf(
77-
'Expected response to be a %s, %s given',
78-
Response::class,
79-
get_class($response)
80-
));
81-
}
82-
8365
$routeMatch = $e->getRouteMatch();
8466
$psr7Request = $this->populateRequestParametersFromRoute(
85-
Psr7ServerRequest::fromZend($request)->withAttribute(RouteMatch::class, $routeMatch),
67+
$this->loadRequest()->withAttribute(RouteMatch::class, $routeMatch),
8668
$routeMatch
8769
);
8870

@@ -98,6 +80,26 @@ function () {
9880
return $result;
9981
}
10082

83+
/**
84+
* @return \Zend\Diactoros\ServerRequest
85+
*
86+
* @throws RuntimeException
87+
*/
88+
private function loadRequest()
89+
{
90+
$request = $this->request;
91+
92+
if (! $request instanceof Request) {
93+
throw new RuntimeException(sprintf(
94+
'Expected request to be a %s, %s given',
95+
Request::class,
96+
get_class($request)
97+
));
98+
}
99+
100+
return Psr7ServerRequest::fromZend($request);
101+
}
102+
101103
/**
102104
* @param ServerRequestInterface $request
103105
* @param RouteMatch|null $routeMatch

0 commit comments

Comments
 (0)