private function handle(Request $request) : Response
    {
        $router = $this->getInstance(Router::class);

        if ($router->match($request->getPathInfo(), $request->getMethod())) { // A match has been found
            /** @var Route $match */
            $match = $router->getMatch();

            // Check if the handler is a closure or not
            $handler = $match->getHandler();

            if (is_object($handler) && $handler instanceof \Closure) {
                try {
                    $content = $this->resolveClosure($handler);
                } catch (\Exception $e) {
                    if (DEVELOPMENT) {
                        showPlainError('Something went wrong while resolving a closure, details below:', false);
                        pr($e);
                        exit;
                    }

                    return $this->respond(500);
                }
            } else {
                $controller = substr($handler, 0, stripos($handler, '.'));
                $method = substr($handler, (stripos($handler, '.') + 1));

                try {
                    $instance = $this->getInstance($controller);
                    if (method_exists($instance, 'setCrispySystem')) {
                        $instance->setCrispySystem($this);
                    }
                    $content = $this->resolveMethod($instance, $method, $match->getParameters());
                } catch (\Exception $e) {
                    if (DEVELOPMENT) {
                        showPlainError('Something went wrong while resolving a controller, details below:', false);
                        pr($e);
                        exit;
                    }

                    return $this->respond(500);
                }
            }

            return $this->respond(200, $content);
        }

        // No match found
        return $this->respond(404);
    }
private function handle(Request $request) : Response
    {
        $router = $this->getInstance(Router::class);

        if ($router->match($request->getPathInfo(), $request->getMethod())) { // A match has been found
            /** @var Route $match */
            $match = $router->getMatch();

            // Check if the handler is a closure or not
            $handler = $match->getHandler();

            if (is_object($handler) && $handler instanceof \Closure) {
                try {
                    $content = $this->resolveClosure($handler);
                } catch (\Exception $e) {
                    if (DEVELOPMENT) {
                        showPlainError('Something went wrong while resolving a closure, details below:', false);
                        pr($e);
                        exit;
                    }

                    return $this->respond(500);
                }
            } else {
                $controller = substr($handler, 0, stripos($handler, '.'));
                $method = substr($handler, (stripos($handler, '.') + 1));

                try {
                    $instance = $this->getInstance($controller);
                    if (method_exists($instance, 'setCrispySystem')) {
                        $instance->setCrispySystem($this);
                    }
                    $content = $this->resolveMethod($instance, $method, $match->getParameters());
                } catch (\Exception $e) {
                    if (DEVELOPMENT) {
                        showPlainError('Something went wrong while resolving a controller, details below:', false);
                        pr($e);
                        exit;
                    }

                    return $this->respond(500);
                }
            }

            return $this->respond(200, $content);
        }

        // No match found
        return $this->respond(404);
    }
private function handle ( Request $ request ) : Response { $ router = $ this -> getInstance ( Router :: class ) ; if ( $ router -> match ( $ request -> getPathInfo ( ) , $ request -> getMethod ( ) ) ) { // A match has been found /** @var Route $match */ $ match = $ router -> getMatch ( ) ; // Check if the handler is a closure or not $ handler = $ match -> getHandler ( ) ; if ( is_object ( $ handler ) && $ handler instanceof \ Closure ) { try { $ content = $ this -> resolveClosure ( $ handler ) ; } catch ( \ Exception $ e ) { if ( DEVELOPMENT ) { showPlainError ( 'Something went wrong while resolving a closure, details below:' , false ) ; pr ( $ e ) ; exit ; } return $ this -> respond ( 500 ) ; } } else { $ controller = substr ( $ handler , 0 , stripos ( $ handler , '.' ) ) ; $ method = substr ( $ handler , ( stripos ( $ handler , '.' ) + 1 ) ) ; try { $ instance = $ this -> getInstance ( $ controller ) ; if ( method_exists ( $ instance , 'setCrispySystem' ) ) { $ instance -> setCrispySystem ( $ this ) ; } $ content = $ this -> resolveMethod ( $ instance , $ method , $ match -> getParameters ( ) ) ; } catch ( \ Exception $ e ) { if ( DEVELOPMENT ) { showPlainError ( 'Something went wrong while resolving a controller, details below:' , false ) ; pr ( $ e ) ; exit ; } return $ this -> respond ( 500 ) ; } } return $ this -> respond ( 200 , $ content ) ; } // No match found return $ this -> respond ( 404 ) ; }
Turn a request into a response
@param Request $request
@return Response
@since 1.0.0
Turn a request into a response