src/FrameworkHandler.php
public function handler(string $root, FrameworkHandler $handler = null): FrameworkHandler
    {
        //if we have this handler in memory
        if (isset($this->handlers[$root])) {
            //if a handler was provided
            if ($handler instanceof FrameworkHandler) {
                //we mean to change up the handler
                $this->handlers[$root] = $handler;
            }

            //either way return the handler
            return $this->handlers[$root];
        }

        //otherwise the handler is not in memory
        if (!($handler instanceof FrameworkHandler)) {
            // By default
            //  - Routes are unique per Handler.
            //  - Middleware are unique per Handler.
            //  - Child pre processors aren't triggered.
            //  - Child post processors aren't triggered.
            //  - Child error processors are set by Parent.
            //  - Child protocols are set by Parent.
            //  - Child packages are set by Parent.
            //  - Child requests are set by Parent.
            //  - Child responses are set by Parent.
            //  - Events are still global.
            $handler = FrameworkHandler::i()->setParent($this);
        }

        //remember the handler
        $this->handlers[$root] = $handler;

        //since this is out first time with this,
        //lets have the parent listen to the root and all possible
        $this->all($root . '**', function ($request, $response) use ($root) {
            //we need the original path
            $path = $request->getPath('string');
            //determine the sub route
            $route = substr($path, strlen($root));

            //because substr('/', 1); --> false
            if (!is_string($route) || !strlen($route)) {
                $route = '/';
            }

            //set up the sub rout in request
            $request->setPath($route);

            //we want to lazy load this in because it is
            //possible that the hander could have changed
            $this->handler($root)
                ->setRequest($request)
                ->setResponse($response)
                ->process();

            //bring the path back
            $request->setPath($path);
        });

        return $this->handlers[$root];
    }
public function handler(string $root, FrameworkHandler $handler = null): FrameworkHandler
    {
        //if we have this handler in memory
        if (isset($this->handlers[$root])) {
            //if a handler was provided
            if ($handler instanceof FrameworkHandler) {
                //we mean to change up the handler
                $this->handlers[$root] = $handler;
            }

            //either way return the handler
            return $this->handlers[$root];
        }

        //otherwise the handler is not in memory
        if (!($handler instanceof FrameworkHandler)) {
            // By default
            //  - Routes are unique per Handler.
            //  - Middleware are unique per Handler.
            //  - Child pre processors aren't triggered.
            //  - Child post processors aren't triggered.
            //  - Child error processors are set by Parent.
            //  - Child protocols are set by Parent.
            //  - Child packages are set by Parent.
            //  - Child requests are set by Parent.
            //  - Child responses are set by Parent.
            //  - Events are still global.
            $handler = FrameworkHandler::i()->setParent($this);
        }

        //remember the handler
        $this->handlers[$root] = $handler;

        //since this is out first time with this,
        //lets have the parent listen to the root and all possible
        $this->all($root . '**', function ($request, $response) use ($root) {
            //we need the original path
            $path = $request->getPath('string');
            //determine the sub route
            $route = substr($path, strlen($root));

            //because substr('/', 1); --> false
            if (!is_string($route) || !strlen($route)) {
                $route = '/';
            }

            //set up the sub rout in request
            $request->setPath($route);

            //we want to lazy load this in because it is
            //possible that the hander could have changed
            $this->handler($root)
                ->setRequest($request)
                ->setResponse($response)
                ->process();

            //bring the path back
            $request->setPath($path);
        });

        return $this->handlers[$root];
    }
public function handler ( string $ root , FrameworkHandler $ handler = null ) : FrameworkHandler { //if we have this handler in memory if ( isset ( $ this -> handlers [ $ root ] ) ) { //if a handler was provided if ( $ handler instanceof FrameworkHandler ) { //we mean to change up the handler $ this -> handlers [ $ root ] = $ handler ; } //either way return the handler return $ this -> handlers [ $ root ] ; } //otherwise the handler is not in memory if ( ! ( $ handler instanceof FrameworkHandler ) ) { // By default //  - Routes are unique per Handler. //  - Middleware are unique per Handler. //  - Child pre processors aren't triggered. //  - Child post processors aren't triggered. //  - Child error processors are set by Parent. //  - Child protocols are set by Parent. //  - Child packages are set by Parent. //  - Child requests are set by Parent. //  - Child responses are set by Parent. //  - Events are still global. $ handler = FrameworkHandler :: i ( ) -> setParent ( $ this ) ; } //remember the handler $ this -> handlers [ $ root ] = $ handler ; //since this is out first time with this, //lets have the parent listen to the root and all possible $ this -> all ( $ root . '**' , function ( $ request , $ response ) use ( $ root ) { //we need the original path $ path = $ request -> getPath ( 'string' ) ; //determine the sub route $ route = substr ( $ path , strlen ( $ root ) ) ; //because substr('/', 1); --> false if ( ! is_string ( $ route ) || ! strlen ( $ route ) ) { $ route = '/' ; } //set up the sub rout in request $ request -> setPath ( $ route ) ; //we want to lazy load this in because it is //possible that the hander could have changed $ this -> handler ( $ root ) -> setRequest ( $ request ) -> setResponse ( $ response ) -> process ( ) ; //bring the path back $ request -> setPath ( $ path ) ; } ) ; return $ this -> handlers [ $ root ] ; }
Sets up a sub handler given the path.

@param *string               $root The root path to handle
@param FrameworkHandler|null $handler the child handler

@return FrameworkHandler
Sets up a sub handler given the path .