public function run()
    {
        // Firstly make sure, default is set
        if (!isset($this->config['components']['router']['default'])) {
            throw new RuntimeException('You should provide default controller for router');
        }

        $sl = $this->bootstrap();

        // Grab required services to run the application
        $request = $sl->get('request');
        $dispatcher = $sl->get('dispatcher');
        $response = $sl->get('response');

        // Do we need to perform SSL redirect?
        if (isset($this->config['components']['router']['ssl']) && $this->config['components']['router']['ssl'] == true) {
            $request->sslRedirect();
        }

        // We will start from route matching firstly
        $router = new Router();

        // Returns RouteMatch on success, false on failure
        $route = $router->match($request->getURI(), $dispatcher->getURIMap());
        $notFound = false;

        // $route is false on failure, otherwise RouteMatch is returned when found
        if ($route !== false) {
            $content = null;

            try {
                $content = $dispatcher->render($route->getMatchedURITemplate(), $route->getVariables());
            } catch(\DomainException $e){
                $notFound = true;
            }

            if ($content === false) {
                // Returning false from an action, will trigger 404
                $notFound = true;
            }

        } else {
            $notFound = true;
        }

        // Handle now found now
        if ($notFound === true) {
            $default = $this->config['components']['router']['default'];

            if (is_string($default)) {
                $notation = new RouteNotation();
                $args = $notation->toArgs($default);

                // Extract controller and action from $args
                $controller = $args[0];
                $action = $args[1];
                
                // Finally call it
                $content = $dispatcher->call($controller, $action);

            } else if (is_callable($default)) {
                $content = call_user_func($default, $sl);
            } else {
                throw new LogicException(sprintf(
                    'Default route must be either callable or a string that represents default controller, not %s', gettype($default)
                ));
            }

            $response->setStatusCode(404);
        }

        $response->send($content);
    }
public function run()
    {
        // Firstly make sure, default is set
        if (!isset($this->config['components']['router']['default'])) {
            throw new RuntimeException('You should provide default controller for router');
        }

        $sl = $this->bootstrap();

        // Grab required services to run the application
        $request = $sl->get('request');
        $dispatcher = $sl->get('dispatcher');
        $response = $sl->get('response');

        // Do we need to perform SSL redirect?
        if (isset($this->config['components']['router']['ssl']) && $this->config['components']['router']['ssl'] == true) {
            $request->sslRedirect();
        }

        // We will start from route matching firstly
        $router = new Router();

        // Returns RouteMatch on success, false on failure
        $route = $router->match($request->getURI(), $dispatcher->getURIMap());
        $notFound = false;

        // $route is false on failure, otherwise RouteMatch is returned when found
        if ($route !== false) {
            $content = null;

            try {
                $content = $dispatcher->render($route->getMatchedURITemplate(), $route->getVariables());
            } catch(\DomainException $e){
                $notFound = true;
            }

            if ($content === false) {
                // Returning false from an action, will trigger 404
                $notFound = true;
            }

        } else {
            $notFound = true;
        }

        // Handle now found now
        if ($notFound === true) {
            $default = $this->config['components']['router']['default'];

            if (is_string($default)) {
                $notation = new RouteNotation();
                $args = $notation->toArgs($default);

                // Extract controller and action from $args
                $controller = $args[0];
                $action = $args[1];
                
                // Finally call it
                $content = $dispatcher->call($controller, $action);

            } else if (is_callable($default)) {
                $content = call_user_func($default, $sl);
            } else {
                throw new LogicException(sprintf(
                    'Default route must be either callable or a string that represents default controller, not %s', gettype($default)
                ));
            }

            $response->setStatusCode(404);
        }

        $response->send($content);
    }
public function run ( ) { // Firstly make sure, default is set if ( ! isset ( $ this -> config [ 'components' ] [ 'router' ] [ 'default' ] ) ) { throw new RuntimeException ( 'You should provide default controller for router' ) ; } $ sl = $ this -> bootstrap ( ) ; // Grab required services to run the application $ request = $ sl -> get ( 'request' ) ; $ dispatcher = $ sl -> get ( 'dispatcher' ) ; $ response = $ sl -> get ( 'response' ) ; // Do we need to perform SSL redirect? if ( isset ( $ this -> config [ 'components' ] [ 'router' ] [ 'ssl' ] ) && $ this -> config [ 'components' ] [ 'router' ] [ 'ssl' ] == true ) { $ request -> sslRedirect ( ) ; } // We will start from route matching firstly $ router = new Router ( ) ; // Returns RouteMatch on success, false on failure $ route = $ router -> match ( $ request -> getURI ( ) , $ dispatcher -> getURIMap ( ) ) ; $ notFound = false ; // $route is false on failure, otherwise RouteMatch is returned when found if ( $ route !== false ) { $ content = null ; try { $ content = $ dispatcher -> render ( $ route -> getMatchedURITemplate ( ) , $ route -> getVariables ( ) ) ; } catch ( \ DomainException $ e ) { $ notFound = true ; } if ( $ content === false ) { // Returning false from an action, will trigger 404 $ notFound = true ; } } else { $ notFound = true ; } // Handle now found now if ( $ notFound === true ) { $ default = $ this -> config [ 'components' ] [ 'router' ] [ 'default' ] ; if ( is_string ( $ default ) ) { $ notation = new RouteNotation ( ) ; $ args = $ notation -> toArgs ( $ default ) ; // Extract controller and action from $args $ controller = $ args [ 0 ] ; $ action = $ args [ 1 ] ; // Finally call it $ content = $ dispatcher -> call ( $ controller , $ action ) ; } else if ( is_callable ( $ default ) ) { $ content = call_user_func ( $ default , $ sl ) ; } else { throw new LogicException ( sprintf ( 'Default route must be either callable or a string that represents default controller, not %s' , gettype ( $ default ) ) ) ; } $ response -> setStatusCode ( 404 ) ; } $ response -> send ( $ content ) ; }
Bootstraps and runs the application!

@return void
Bootstraps and runs the application!