@@ -97,35 +97,7 @@ public function processRequest(ServerRequestInterface $request, ResponseInterfac
9797 */
9898 public function dispatch (RestRequestInterface $ request , ResponseInterface $ response )
9999 {
100- $ requestPath = $ request ->getPath ();
101- if (!$ requestPath || $ requestPath === '/ ' ) {
102- return $ this ->greet ($ request );
103- }
104-
105- // Checks if the request needs authentication
106- $ access = $ this ->objectManager ->getAccessController ()->getAccess ($ request );
107- switch (true ) {
108- case $ access ->isAllowed ():
109- case $ access ->isAuthorized ():
110- break ;
111-
112- case $ access ->isUnauthorized ():
113- return $ this ->responseFactory ->createErrorResponse ('Unauthorized ' , 401 , $ request );
114-
115- case $ access ->isDenied ():
116- default :
117- return $ this ->responseFactory ->createErrorResponse ('Forbidden ' , 403 , $ request );
118- }
119-
120- $ newResponse = $ this ->getCachedResponseOrCallHandler ($ request , $ response );
121- $ newResponse = $ this ->addAdditionalHeaders ($ newResponse );
122-
123- $ this ->logger ->logResponse (
124- 'response: ' . $ newResponse ->getStatusCode (),
125- ['response ' => (string )$ newResponse ->getBody ()]
126- );
127-
128- return $ newResponse ;
100+ return $ this ->addAdditionalHeaders ($ this ->dispatchInternal ($ request , $ response ));
129101 }
130102
131103 /**
@@ -270,4 +242,41 @@ private function addAdditionalHeaders(ResponseInterface $response)
270242
271243 return $ response ;
272244 }
245+
246+ /**
247+ * @param RestRequestInterface $request
248+ * @param ResponseInterface $response
249+ * @return ResponseInterface
250+ */
251+ private function dispatchInternal (RestRequestInterface $ request , ResponseInterface $ response ): ResponseInterface
252+ {
253+ $ requestPath = $ request ->getPath ();
254+ if (!$ requestPath || $ requestPath === '/ ' ) {
255+ return $ this ->greet ($ request );
256+ }
257+
258+ // Checks if the request needs authentication
259+ $ access = $ this ->objectManager ->getAccessController ()->getAccess ($ request );
260+ switch (true ) {
261+ case $ access ->isAllowed ():
262+ case $ access ->isAuthorized ():
263+ break ;
264+
265+ case $ access ->isUnauthorized ():
266+ return $ this ->responseFactory ->createErrorResponse ('Unauthorized ' , 401 , $ request );
267+
268+ case $ access ->isDenied ():
269+ default :
270+ return $ this ->responseFactory ->createErrorResponse ('Forbidden ' , 403 , $ request );
271+ }
272+
273+ $ newResponse = $ this ->getCachedResponseOrCallHandler ($ request , $ response );
274+
275+ $ this ->logger ->logResponse (
276+ 'response: ' . $ newResponse ->getStatusCode (),
277+ ['response ' => (string )$ newResponse ->getBody ()]
278+ );
279+
280+ return $ newResponse ;
281+ }
273282}
0 commit comments