Callback launcher

@param  callable|string|array $actions
@param  mixed  $param

@return mixed

@throws RouterException
174732
public function call($actions, $param = null)
    {
        $param = (array) $param;

        /**
         * We execute the action define as a string
         */
        if (is_string($actions) || is_callable($actions)) {
            $actions = [$actions];
        }

        if (!is_array($actions)) {
            throw new \InvalidArgumentException(
                'Le premier paramètre doit être un tableau, une chaine ou une closure',
                E_USER_ERROR
            );
        }

        $middlewares = [];

        /**
         * We verify the existence of middleware associated with the action
         * and extracting the middleware
         */
        if (isset($actions['middleware'])) {
            $middlewares = (array) $actions['middleware'];

            unset($actions['middleware']);
        }

        /**
         * We verify the existence of controller associated
         * with the action and extracting the controller
         */
        if (isset($actions['controller'])) {
            $actions = (array) $actions['controller'];
        }

        $functions = [];

        /**
         * We normalize of the action to execute and
         * creation of the dependency injection
         */
        foreach ($actions as $key => $action) {
            if (is_string($action)) {
                array_push($functions, $this->controller($action));

                continue;
            }

            if (! is_callable($action)) {
                continue;
            }

            if (is_array($action) && $action[0] instanceof \Closure) {
                $injection = $this->injectorForClosure($action[0]);
            } else {
                $injection = $this->injectorForClosure($action);
            }

            array_push($functions, ['action' => $action, 'injection' => $injection]);
        }

        /**
         * We load the middleware associated with the action
         */
        foreach ($middlewares as $middleware) {
            if (is_callable($middleware)) {
                if ($middleware instanceof \Closure || is_array($middleware)) {
                    $this->dispatcher->pipe($middleware);

                    continue;
                }
            }

            if (class_exists($middleware)) {
                $this->dispatcher->pipe($middleware);

                continue;
            }
            
            $parts = [];

            if (is_string($middleware)) {
                $parts = explode(':', $middleware, 2);

                $middleware = $parts[0];
            }

            if (!array_key_exists($middleware, $this->middlewares)) {
                throw new RouterException(sprintf('%s n\'est pas un middleware définir.', $middleware), E_ERROR);
            }

            // We check if the defined middleware is a valid middleware.
            if (!class_exists($this->middlewares[$middleware])) {
                throw new RouterException(sprintf('%s n\'est pas un class middleware.', $middleware));
            }

            // We qdd middleware into dispatch pipeline
            $this->dispatcher->pipe(
                $this->middlewares[$middleware],
                count($parts) != 2 ? [] : explode(',', $parts[1])
            );
        }

        // We process middleware througth the dispatcher
        $response = $this->dispatcher->process(
            Request::getInstance()
        );

        switch (true) {
            case is_null($response):
            case is_string($response):
            case is_array($response):
            case is_object($response):
            case $response instanceof \Iterable:
            case $response instanceof ResponseInterface:
                return $response;
            case $response instanceof Model || $response instanceof Collection:
                return $response->toArray();
        }

        return $this->dispatchControllers($functions, $param);
    }
265202
public Api getActionResult(String action, String params) throws Exception {
    Api result = this.getActionResult(action, params, null, null);
    return result;
  }
791171
public function back($actions='insert|update|do_delete', $url="")
    {

        if ($url == "") {
            if (count($this->links)) {
                $url = array_pop($this->links);
            } else {
                return $this;
            }
        } else {
            $base = str_replace(Request::path(),'',strtok(Request::fullUrl(),'?'));
            $match_url = str_replace($base, '/', strtok($url,'?'));
            if (Request::path()!= $match_url) {
                $url = Persistence::get($match_url);
            }
        }

        $this->back_on = explode("|", $actions);
        $this->back_url = $url;

        return $this;
    }
173099
public function map($method, $action, $callback){
		$route = new Route($method, $action, $callback);
		array_push($this->routes, $route);
		return $route;
	}
38374
protected function redirect($module, $action = "index", $params = array())
  {
    $module = $this->app->getModuleKey() . "=" . $module;
    $action = $action != "index" ? '&' . $this->app->getActionKey() . "=" . $action : "";

    foreach($params as $key => $val)
    {
      $action .= "&" . $key . "=" . $val;
    }

    header("Location: " . TeamSpeak3_Helper_Uri::getBaseUri() . "?" . $module . $action);

    exit;
  }
474189
public function runAs($routeName, $params = [])
    {
        if (!isset($this->routings[$routeName])) {
            throw new \Exception("Route name '{$routeName}' not found!");
        }

        // populate handler queue
        $handler = end($this->routings[$routeName]);
        $this->appendHandlerQueue($handler);

        // Run everything in handler queue
        $output = null;
        while ($handler = array_shift($this->handlerQueue)) {
            $output = $this->executeHandler($handler, $params, $output);
        }
        echo $this->get('view');

        return $output;
    }
798759
public function actions($actions)
    {
        if ($actions instanceof Closure) {
            $this->actionsCallback = $actions;
        }

        if (is_string($actions) && is_subclass_of($actions, Displayers\Actions::class)) {
            $this->actionsClass = $actions;
        }

        return $this;
    }
886860
public Object call(Map<String, ?> params) throws Throwable {
    return AnnotatedExtensions.exec(getCallMethod(), getParameterNames(), params, this);
  }
916155
public function action($action, $parameters = [], $absolute = true)
    {
        if (is_null($route = $this->routes->getByAction($action = $this->formatAction($action)))) {
            throw new InvalidArgumentException("Action {$action} not defined.");
        }

        return $this->toRoute($route, $parameters, $absolute);
    }
226325
public function dispatch($action, array $parameters = [])
    {
        return $this->server->dispatch(
            new Request($action, $parameters)
        )->getData();
    }
912159
private function createActions($actions)
    {
        $actionBuilders = [];

        foreach ($actions as $action) {
            switch (strtolower($action->type)) {
                case Action::TYPE_POSTBACK:
                    $actionBuilders[] = new PostbackTemplateActionBuilder($action->label, $action->value);
                    break;
                case Action::TYPE_URI:
                    $actionBuilders[] = new UriTemplateActionBuilder($action->label, $action->value);
                    break;
                default:
                    $actionBuilders[] = new MessageTemplateActionBuilder($action->label, $action->value);
            }
        }

        return $actionBuilders;
    }
402028
public function invokeAction(array $params)
    {
        if (!$this->inited) {
            throw new \wf\app\web\Exception('请在'.get_called_class().'::__construct()调用parent::__construct()');
        }

        $action = $this->act . 'Action';

        if(!method_exists($this, $action)) {
            throw new \wf\app\web\NotFoundException;
        }

        // 执行方法
        //call_user_func_array(array($this, $action), $params);
        $method = new \ReflectionMethod($this, $action);
        if (!$method->isPublic()){
            // note：ReflectionException为“Fatal error”，不可捕获，不在这里抛出，也不直接在上一级异常中捕获而不用这个异常抛出
            // 否则不能在上一级异常处理中捕获，而直接到顶级异常处理中
            throw new \wf\app\web\NotFoundException;
        }

        $method->invokeArgs($this, $params); // 在这里加断点，下一步将进入当前请求的控制器业务逻辑中
    }
199521
public function getNewActionEvent(string $name = null, $target = null, $params = null): ActionEvent
    {
        if ($name === null) {
            $name = 'action_event';
        }

        return new DefaultActionEvent($name, $target, $params);
    }
199916
protected function forward(string $controller, array $action = [], array $params = [])
    {
        return $this->dispatcher->forward([
            'handler' => $controller,
            'action' => $action,
            'params' => $params,
        ]);
    }
428324
public static function customDispatcher($className, $action, $params)
    {
        $dispatcher = new self;
        $dispatcher->setClassName($className);
        $dispatcher->setAction($action);
        $dispatcher->setParams($params);

        return $dispatcher;
    }
999869
protected function execPageAction($actionName, $parameters)
    {
        $result = null;

        if (!$this->actionExists($actionName)) {
            if (Config::get('app.debug', false)) {
                throw new SystemException(sprintf(
                    "Action %s is not found in the controller %s",
                    $actionName,
                    get_class($this)
                ));
            } else {
                Response::make(View::make('backend::404'), 404);
            }
        }

        // Execute the action
        $result = call_user_func_array([$this, $actionName], $parameters);

        // Expecting \Response and \RedirectResponse
        if ($result instanceof \Symfony\Component\HttpFoundation\Response) {
            return $result;
        }

        // No page title
        if (!$this->pageTitle) {
            $this->pageTitle = 'backend::lang.page.untitled';
        }

        // Load the view
        if (!$this->suppressView && $result === null) {
            return $this->makeView($actionName);
        }

        return $this->makeViewContent($result);
    }
987348
protected function redirectAction ($action, $params=array())
    {
        // Get controller public name
        $ctrlPubName = \Teon\Base\Stdlib\ClassUtils::getPublicControllerName(get_class($this));

        // Get original parameters
        $paramsOrig = $this->params()->fromRoute();

        // Combine parameters - if action is explicitly specified in params it is overriden
        $params2pass = array_merge(
            $paramsOrig,
            $params,
            array('action' => $action)
        );

        // Do the redirect
        return $this->redirect()->toRoute($ctrlPubName, $params2pass);
    }