src/Application.php
public function run()
    {
        $request = $this->request;
        $response = $this->response;
        $config = $this->configuration;

        $httpMethod = $request->getMethod();
        $pathInfo = $request->getUri()->getPath();
        if (empty($pathInfo)) {
            $pathInfo = '/';
        }

        $routeObject = $this->router->resolve($pathInfo, $httpMethod);
        if($routeObject) {
            $middlewareList = [];
            if (isset($routeObject['middleware'])) {
                $middlewareConfig = $config->get('middlewares');
                $middlewareCount = count($routeObject['middleware']);
                $middlewareNext = null;
                $middlewareFactory = $this->container->get(MiddlewareFactory::class);

                for ($i=$middlewareCount-1; $i >= 0; $i--) {
                    $middlewareName = $routeObject['middleware'][$i];
                    $middlewareClass = $middlewareConfig[$middlewareName];
                    $middlewareList[$i] = $middlewareFactory->createObject($middlewareClass, [
                        'response' => $response,
                        'next' => $middlewareNext,
                    ]);
                    $middlewareNext = $middlewareList[$i];
                }
            }

            $baseNamespace = $config->get('controllersNamespace');
            $handler = $this->convertCallbackToClosure($routeObject['handler'], $baseNamespace);
            $params = isset($routeObject['params']) ? $routeObject['params'] : [];
            $requestHandler = new ServerRequestHandler($response, $handler, $routeObject['params']);

            if (isset($middlewareList[0])) {
                $response = $middlewareList[0]->process($request, $requestHandler);
            } else {
                $response = $requestHandler->handle($request);
            }

        } else {
            throw new HttpException(404, "Route '{$pathInfo}' not found");
        }

        $this->emitResponse($response);
    }
public function run()
    {
        $request = $this->request;
        $response = $this->response;
        $config = $this->configuration;

        $httpMethod = $request->getMethod();
        $pathInfo = $request->getUri()->getPath();
        if (empty($pathInfo)) {
            $pathInfo = '/';
        }

        $routeObject = $this->router->resolve($pathInfo, $httpMethod);
        if($routeObject) {
            $middlewareList = [];
            if (isset($routeObject['middleware'])) {
                $middlewareConfig = $config->get('middlewares');
                $middlewareCount = count($routeObject['middleware']);
                $middlewareNext = null;
                $middlewareFactory = $this->container->get(MiddlewareFactory::class);

                for ($i=$middlewareCount-1; $i >= 0; $i--) {
                    $middlewareName = $routeObject['middleware'][$i];
                    $middlewareClass = $middlewareConfig[$middlewareName];
                    $middlewareList[$i] = $middlewareFactory->createObject($middlewareClass, [
                        'response' => $response,
                        'next' => $middlewareNext,
                    ]);
                    $middlewareNext = $middlewareList[$i];
                }
            }

            $baseNamespace = $config->get('controllersNamespace');
            $handler = $this->convertCallbackToClosure($routeObject['handler'], $baseNamespace);
            $params = isset($routeObject['params']) ? $routeObject['params'] : [];
            $requestHandler = new ServerRequestHandler($response, $handler, $routeObject['params']);

            if (isset($middlewareList[0])) {
                $response = $middlewareList[0]->process($request, $requestHandler);
            } else {
                $response = $requestHandler->handle($request);
            }

        } else {
            throw new HttpException(404, "Route '{$pathInfo}' not found");
        }

        $this->emitResponse($response);
    }
public function run ( ) { $ request = $ this -> request ; $ response = $ this -> response ; $ config = $ this -> configuration ; $ httpMethod = $ request -> getMethod ( ) ; $ pathInfo = $ request -> getUri ( ) -> getPath ( ) ; if ( empty ( $ pathInfo ) ) { $ pathInfo = '/' ; } $ routeObject = $ this -> router -> resolve ( $ pathInfo , $ httpMethod ) ; if ( $ routeObject ) { $ middlewareList = [ ] ; if ( isset ( $ routeObject [ 'middleware' ] ) ) { $ middlewareConfig = $ config -> get ( 'middlewares' ) ; $ middlewareCount = count ( $ routeObject [ 'middleware' ] ) ; $ middlewareNext = null ; $ middlewareFactory = $ this -> container -> get ( MiddlewareFactory :: class ) ; for ( $ i = $ middlewareCount - 1 ; $ i >= 0 ; $ i -- ) { $ middlewareName = $ routeObject [ 'middleware' ] [ $ i ] ; $ middlewareClass = $ middlewareConfig [ $ middlewareName ] ; $ middlewareList [ $ i ] = $ middlewareFactory -> createObject ( $ middlewareClass , [ 'response' => $ response , 'next' => $ middlewareNext , ] ) ; $ middlewareNext = $ middlewareList [ $ i ] ; } } $ baseNamespace = $ config -> get ( 'controllersNamespace' ) ; $ handler = $ this -> convertCallbackToClosure ( $ routeObject [ 'handler' ] , $ baseNamespace ) ; $ params = isset ( $ routeObject [ 'params' ] ) ? $ routeObject [ 'params' ] : [ ] ; $ requestHandler = new ServerRequestHandler ( $ response , $ handler , $ routeObject [ 'params' ] ) ; if ( isset ( $ middlewareList [ 0 ] ) ) { $ response = $ middlewareList [ 0 ] -> process ( $ request , $ requestHandler ) ; } else { $ response = $ requestHandler -> handle ( $ request ) ; } } else { throw new HttpException ( 404 , "Route '{$pathInfo}' not found" ) ; } $ this -> emitResponse ( $ response ) ; }
Runs application to handle request.
Runs application to handle request .