public function loadCallable($matches = array(), $route): bool
    {
        $this->logger->newLevel('Loading callable');

        // Fire the event to notify our modules
        $event = Events::fireEvent('routerLoadCallableEvent', $this->callable, $matches, $route);

        // The event has been cancelled
        if ($event->isCancelled()) {
            return false;
        }

        // Prepare the arguments and add the route
        $args = $event->matches;
        $args['route'] = $event->route;

        if (!is_callable($event->callable)) {
            if (isset($event->callable['controller'])) {
                // Reset the arguments and fetch from custom callable
                $args = array();
                $args['controller'] = isset($event->callable['controller']) ? $event->callable['controller'] : (isset($matches['controller']) ? $matches['controller'] : null);
                $args['function'] = isset($event->callable['function'])   ? $event->callable['function']   : (isset($matches['function']) ? $matches['function'] : null);
                $args['parameters'] = isset($event->callable['parameters']) ? $event->callable['parameters'] : (isset($matches['parameters']) ? explode('/', $matches['parameters']) : null);

                $this->callable = array('\FuzeWorks\Router', 'defaultCallable');
            } else {
                $this->logger->log('The given callable is not callable!', E_ERROR);
                $this->logger->http_error(500);
                $this->logger->stopLevel();

                return true;
            }
        } else {
            $this->callable = $event->callable;
        }

        // And log the input to the logger
        $this->logger->newLevel('Calling callable');
        foreach ($args as $key => $value) {
            $this->logger->log($key.': '.var_export($value, true).'');
        }
        $this->logger->stopLevel();

        $skip = call_user_func_array($this->callable, array($args)) === true;

        if (!$skip) {
            $this->logger->log('Callable not satisfied, skipping to next callable');
        }

        $this->logger->stopLevel();

        return $skip;
    }
public function loadCallable($matches = array(), $route): bool
    {
        $this->logger->newLevel('Loading callable');

        // Fire the event to notify our modules
        $event = Events::fireEvent('routerLoadCallableEvent', $this->callable, $matches, $route);

        // The event has been cancelled
        if ($event->isCancelled()) {
            return false;
        }

        // Prepare the arguments and add the route
        $args = $event->matches;
        $args['route'] = $event->route;

        if (!is_callable($event->callable)) {
            if (isset($event->callable['controller'])) {
                // Reset the arguments and fetch from custom callable
                $args = array();
                $args['controller'] = isset($event->callable['controller']) ? $event->callable['controller'] : (isset($matches['controller']) ? $matches['controller'] : null);
                $args['function'] = isset($event->callable['function'])   ? $event->callable['function']   : (isset($matches['function']) ? $matches['function'] : null);
                $args['parameters'] = isset($event->callable['parameters']) ? $event->callable['parameters'] : (isset($matches['parameters']) ? explode('/', $matches['parameters']) : null);

                $this->callable = array('\FuzeWorks\Router', 'defaultCallable');
            } else {
                $this->logger->log('The given callable is not callable!', E_ERROR);
                $this->logger->http_error(500);
                $this->logger->stopLevel();

                return true;
            }
        } else {
            $this->callable = $event->callable;
        }

        // And log the input to the logger
        $this->logger->newLevel('Calling callable');
        foreach ($args as $key => $value) {
            $this->logger->log($key.': '.var_export($value, true).'');
        }
        $this->logger->stopLevel();

        $skip = call_user_func_array($this->callable, array($args)) === true;

        if (!$skip) {
            $this->logger->log('Callable not satisfied, skipping to next callable');
        }

        $this->logger->stopLevel();

        return $skip;
    }
public function loadCallable ( $ matches = array ( ) , $ route ) : bool { $ this -> logger -> newLevel ( 'Loading callable' ) ; // Fire the event to notify our modules $ event = Events :: fireEvent ( 'routerLoadCallableEvent' , $ this -> callable , $ matches , $ route ) ; // The event has been cancelled if ( $ event -> isCancelled ( ) ) { return false ; } // Prepare the arguments and add the route $ args = $ event -> matches ; $ args [ 'route' ] = $ event -> route ; if ( ! is_callable ( $ event -> callable ) ) { if ( isset ( $ event -> callable [ 'controller' ] ) ) { // Reset the arguments and fetch from custom callable $ args = array ( ) ; $ args [ 'controller' ] = isset ( $ event -> callable [ 'controller' ] ) ? $ event -> callable [ 'controller' ] : ( isset ( $ matches [ 'controller' ] ) ? $ matches [ 'controller' ] : null ) ; $ args [ 'function' ] = isset ( $ event -> callable [ 'function' ] ) ? $ event -> callable [ 'function' ] : ( isset ( $ matches [ 'function' ] ) ? $ matches [ 'function' ] : null ) ; $ args [ 'parameters' ] = isset ( $ event -> callable [ 'parameters' ] ) ? $ event -> callable [ 'parameters' ] : ( isset ( $ matches [ 'parameters' ] ) ? explode ( '/' , $ matches [ 'parameters' ] ) : null ) ; $ this -> callable = array ( '\FuzeWorks\Router' , 'defaultCallable' ) ; } else { $ this -> logger -> log ( 'The given callable is not callable!' , E_ERROR ) ; $ this -> logger -> http_error ( 500 ) ; $ this -> logger -> stopLevel ( ) ; return true ; } } else { $ this -> callable = $ event -> callable ; } // And log the input to the logger $ this -> logger -> newLevel ( 'Calling callable' ) ; foreach ( $ args as $ key => $ value ) { $ this -> logger -> log ( $ key . ': ' . var_export ( $ value , true ) . '' ) ; } $ this -> logger -> stopLevel ( ) ; $ skip = call_user_func_array ( $ this -> callable , array ( $ args ) ) === true ; if ( ! $ skip ) { $ this -> logger -> log ( 'Callable not satisfied, skipping to next callable' ) ; } $ this -> logger -> stopLevel ( ) ; return $ skip ; }
Load the callable to which the route matched.

First it checks if it is possible to call the callable. If not, the default callable gets selected and a controller, function and parameters get selected.

Then the arguments get prepared and finally the callable is called.

@param array   Preg matches with the routing path
@param string  The route that matched

@return bool Whether or not the callable was satisfied
Load the callable to which the route matched .