protected function handleAsControllerAction(array $callable)
    {
        $class = $callable[0];
        $action = $callable[1];
        $args = $callable[2];
        $obj = new $class();

        $refl = new \ReflectionClass($class);
        $diInterface = "Anax\Commons\ContainerInjectableInterface";
        $appInterface = "Anax\Commons\AppInjectableInterface";

        if ($this->di && $refl->implementsInterface($diInterface)) {
            $obj->setDI($this->di);
        } elseif ($this->di && $refl->implementsInterface($appInterface)) {
            if (!$this->di->has("app")) {
                throw new ConfigurationException(
                    "Controller '$class' implements AppInjectableInterface but \$app is not available in \$di."
                );
            }
            $obj->setApp($this->di->get("app"));
        }

        try {
            $refl = new \ReflectionMethod($class, "initialize");
            if ($refl->isPublic()) {
                $obj->initialize();
            }
        } catch (\ReflectionException $e) {
            ;
        }

        $refl = new \ReflectionMethod($obj, $action);
        $paramIsVariadic = false;
        foreach ($refl->getParameters() as $param) {
            if ($param->isVariadic()) {
                $paramIsVariadic = true;
                break;
            }
        }

        if (!$paramIsVariadic
            && $refl->getNumberOfParameters() < count($args)
        ) {
            throw new NotFoundException(
                "Controller '$class' with action method '$action' valid but to many parameters. Got "
                . count($args)
                . ", expected "
                . $refl->getNumberOfParameters() . "."
            );
        }

        try {
            $res = $obj->$action(...$args);
        } catch (\ArgumentCountError $e) {
            throw new NotFoundException($e->getMessage());
        } catch (\TypeError $e) {
            throw new NotFoundException($e->getMessage());
        }

        return $res;
    }
protected function handleAsControllerAction(array $callable)
    {
        $class = $callable[0];
        $action = $callable[1];
        $args = $callable[2];
        $obj = new $class();

        $refl = new \ReflectionClass($class);
        $diInterface = "Anax\Commons\ContainerInjectableInterface";
        $appInterface = "Anax\Commons\AppInjectableInterface";

        if ($this->di && $refl->implementsInterface($diInterface)) {
            $obj->setDI($this->di);
        } elseif ($this->di && $refl->implementsInterface($appInterface)) {
            if (!$this->di->has("app")) {
                throw new ConfigurationException(
                    "Controller '$class' implements AppInjectableInterface but \$app is not available in \$di."
                );
            }
            $obj->setApp($this->di->get("app"));
        }

        try {
            $refl = new \ReflectionMethod($class, "initialize");
            if ($refl->isPublic()) {
                $obj->initialize();
            }
        } catch (\ReflectionException $e) {
            ;
        }

        $refl = new \ReflectionMethod($obj, $action);
        $paramIsVariadic = false;
        foreach ($refl->getParameters() as $param) {
            if ($param->isVariadic()) {
                $paramIsVariadic = true;
                break;
            }
        }

        if (!$paramIsVariadic
            && $refl->getNumberOfParameters() < count($args)
        ) {
            throw new NotFoundException(
                "Controller '$class' with action method '$action' valid but to many parameters. Got "
                . count($args)
                . ", expected "
                . $refl->getNumberOfParameters() . "."
            );
        }

        try {
            $res = $obj->$action(...$args);
        } catch (\ArgumentCountError $e) {
            throw new NotFoundException($e->getMessage());
        } catch (\TypeError $e) {
            throw new NotFoundException($e->getMessage());
        }

        return $res;
    }
protected function handleAsControllerAction ( array $ callable ) { $ class = $ callable [ 0 ] ; $ action = $ callable [ 1 ] ; $ args = $ callable [ 2 ] ; $ obj = new $ class ( ) ; $ refl = new \ ReflectionClass ( $ class ) ; $ diInterface = "Anax\Commons\ContainerInjectableInterface" ; $ appInterface = "Anax\Commons\AppInjectableInterface" ; if ( $ this -> di && $ refl -> implementsInterface ( $ diInterface ) ) { $ obj -> setDI ( $ this -> di ) ; } elseif ( $ this -> di && $ refl -> implementsInterface ( $ appInterface ) ) { if ( ! $ this -> di -> has ( "app" ) ) { throw new ConfigurationException ( "Controller '$class' implements AppInjectableInterface but \$app is not available in \$di." ) ; } $ obj -> setApp ( $ this -> di -> get ( "app" ) ) ; } try { $ refl = new \ ReflectionMethod ( $ class , "initialize" ) ; if ( $ refl -> isPublic ( ) ) { $ obj -> initialize ( ) ; } } catch ( \ ReflectionException $ e ) { ; } $ refl = new \ ReflectionMethod ( $ obj , $ action ) ; $ paramIsVariadic = false ; foreach ( $ refl -> getParameters ( ) as $ param ) { if ( $ param -> isVariadic ( ) ) { $ paramIsVariadic = true ; break ; } } if ( ! $ paramIsVariadic && $ refl -> getNumberOfParameters ( ) < count ( $ args ) ) { throw new NotFoundException ( "Controller '$class' with action method '$action' valid but to many parameters. Got " . count ( $ args ) . ", expected " . $ refl -> getNumberOfParameters ( ) . "." ) ; } try { $ res = $ obj -> $ action ( ... $ args ) ; } catch ( \ ArgumentCountError $ e ) { throw new NotFoundException ( $ e -> getMessage ( ) ) ; } catch ( \ TypeError $ e ) { throw new NotFoundException ( $ e -> getMessage ( ) ) ; } return $ res ; }
Call the controller action with optional arguments and call
initialisation methods if available.

@param string $callable with details on what controller action to call.

@return mixed result from the handler.
Call the controller action with optional arguments and call initialisation methods if available .