Dispatch method

@param  Zend_Server_Method_Definition $invocable
@param  array $params
@return mixed
550482
protected function _dispatch(Zend_Server_Method_Definition $invocable, array $params)
    {
        $callback = $invocable->getCallback();
        $type     = $callback->getType();

        if ('function' == $type) {
            $function = $callback->getFunction();
            return call_user_func_array($function, $params);
        }

        $class  = $callback->getClass();
        $method = $callback->getMethod();

        if ('static' == $type) {
            return call_user_func_array(array($class, $method), $params);
        }

        $object = $invocable->getObject();
        if (!is_object($object)) {
            $invokeArgs = $invocable->getInvokeArguments();
            if (!empty($invokeArgs)) {
                $reflection = new ReflectionClass($class);
                $object     = $reflection->newInstanceArgs($invokeArgs);
            } else {
                $object = new $class;
            }
        }
        return call_user_func_array(array($object, $method), $params);
    }
1218382
function invoke() {
        parent::invoke();

        $result = true;

        // Set own core attributes
        $this->does_generate = ACTION_NONE;

        // These are always here
        global $CFG, $XMLDB;

        // Do the job, setting result as needed

        // Get the dir containing the file
        $dirpath = required_param('dir', PARAM_PATH);
        $dirpath = $CFG->dirroot . $dirpath;
        $unload = optional_param('unload', true, PARAM_BOOL);

        // Get the edited dir
        if (!empty($XMLDB->editeddirs)) {
            if (isset($XMLDB->editeddirs[$dirpath])) {
                $editeddir = $XMLDB->editeddirs[$dirpath];
            }
        }
        // Copy the edited dir over the original one
        if (!empty($XMLDB->dbdirs)) {
            if (isset($XMLDB->dbdirs[$dirpath])) {
                $XMLDB->dbdirs[$dirpath] = unserialize(serialize($editeddir));
                $dbdir = $XMLDB->dbdirs[$dirpath];
            }
        }

        // Check for perms
        if (!is_writeable($dirpath . '/install.xml')) {
            $this->errormsg = $this->str['filenotwriteable'] . '(' . $dirpath . '/install.xml)';
            return false;
        }

        // Save the original dir
        $result = $dbdir->xml_file->saveXMLFile();

        if ($result) {
            // Delete the edited dir
            unset ($XMLDB->editeddirs[$dirpath]);
            // Unload de originaldir
            unset($XMLDB->dbdirs[$dirpath]->xml_file);
            unset($XMLDB->dbdirs[$dirpath]->xml_loaded);
            unset($XMLDB->dbdirs[$dirpath]->xml_changed);
            unset($XMLDB->dbdirs[$dirpath]->xml_exists);
            unset($XMLDB->dbdirs[$dirpath]->xml_writeable);
        } else {
            $this->errormsg = 'Error saving XML file (' . $dirpath . ')';
            return false;
        }

        // If unload has been disabled, simulate it by reloading the file now
        if (!$unload) {
            return $this->launch('load_xml_file');
        }

        // Launch postaction if exists (leave this here!)
        if ($this->getPostAction() && $result) {
            return $this->launch($this->getPostAction());
        }

        // Return ok if arrived here
        return $result;
    }
577291
public function load($invoiceId, $invoiceItemId, $params = [])
    {
        return $this->client()->get(
            'invoices/{invoiceId}/items/{invoiceItemId}',
            ['invoiceId' => $invoiceId, 'invoiceItemId' => $invoiceItemId] + (array) $params
        );
    }
198706
public function dispatch($httpMethod, $uri)
    {
        list($handler, $filters, $vars) = $this->dispatchRoute($httpMethod, trim($uri, '/'));

        list($beforeFilter, $afterFilter) = $this->parseFilters($filters);

        if (($response = $this->dispatchFilters($beforeFilter)) !== null) {
            return $response;
        }

        $resolvedHandler = $this->handlerResolver->resolve($handler);
        $vars['request'] = $this->getRequest();
        $reflection = new ReflectionMethod($resolvedHandler[0], $resolvedHandler[1]);
        $reflectionVariables = $this->getReflectionVars($reflection, $vars);
        $this->authorizeRequest();
        $this->validateRequest($reflectionVariables);
        $response = call_user_func_array(
            $resolvedHandler,
            $reflectionVariables
        );

        return $this->dispatchFilters($afterFilter, $response);
    }
1117686
public function invoke($method, $_ = null)
	{
		$params = func_get_args();
		array_shift($params);

		return $this->invokeArgs($method, $params);
	}
1260926
public function dispatch(int $status, string $path, string $method, $route)
    {
        // not found
        if ($status === RouterInterface::NOT_FOUND) {
            return $this->handleNotFound($path, $method);
        }

        // method not allowed
        if ($status === RouterInterface::METHOD_NOT_ALLOWED) {
            return $this->handleNotAllowed($path, $method, $route);
        }

        // trigger route found event
        $this->fire(self::ON_FOUND, [$path, $route]);

        $result = null;
        $options = $route->getOptions();

        // fire enter event
        // schema,domains ... metadata validate
        if (isset($options['enter']) && false === RouteHelper::call($options['enter'], [$options, $path])) {
            return $result;
        }

        $handler = $route->getHandler();
        $args = $route->getParams();

        try {
            // trigger route exec_start event
            $this->fire(self::ON_EXEC_START, [$path, $route]);

            $globChains = $this->getRouter()->getChains();
            $chains = $route->getChains();

            $result = $this->callHandler($path, $method, $handler, $args);

            // fire leave event
            if (isset($options['leave'])) {
                RouteHelper::call($options['leave'], [$options, $path]);
            }

            // trigger route exec_end event
            $this->fire(self::ON_EXEC_END, [$path, $route, $result]);
        } catch (\Throwable $e) {
            // trigger route exec_error event
            if ($cb = $this->getOption(self::ON_EXEC_ERROR)) {
                return RouteHelper::call($cb, [$e, $path, $route]);
            }

            throw $e;
        }

        return $result;
    }
331232
private Class<?>[] getGroup(Invocable invocable) {
        final List<Class<?>[]> groups = new ArrayList<>();
        for (Parameter parameter : invocable.getParameters()) {
            if (parameter.isAnnotationPresent(Validated.class)) {
                groups.add(parameter.getAnnotation(Validated.class).value());
            }
        }

        switch (groups.size()) {
            // No parameters were annotated with Validated, so validate under the default group
            case 0: return new Class<?>[] {Default.class};

            // A single parameter was annotated with Validated, so use their group
            case 1: return groups.get(0);

            // Multiple parameters were annotated with Validated, so we must check if
            // all groups are equal to each other, if not, throw an exception because
            // the validator is unable to handle parameters validated under different
            // groups. If the parameters have the same group, we can grab the first
            // group.
            default:
                for (int i = 0; i < groups.size(); i++) {
                    for (int j = i; j < groups.size(); j++) {
                        if (!Arrays.deepEquals(groups.get(i), groups.get(j))) {
                            throw new WebApplicationException("Parameters must have the same validation groups in " +
                                invocable.getHandlingMethod().getName(), 500);
                        }
                    }
                }
                return groups.get(0);
        }
    }
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); // 在这里加断点，下一步将进入当前请求的控制器业务逻辑中
    }
1067109
private function dispatchMvc($module, $controller, $action, $params)
    {
        return Dispatcher::mvcDispatcher($module, $controller, $action, $params);
    }
135480
public function callWith($callback, Arguments $arguments)
    {
        if ($callback instanceof Invocable) {
            return $callback->invokeWith($arguments);
        }

        $arguments = $arguments->all();

        return $callback(...$arguments);
    }
829442
public static function dispatch()
    {

        $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        $method = $_SERVER['REQUEST_METHOD'];

        $searches = array_keys(static::$patterns);
        $replaces = array_values(static::$patterns);

        self::$routes = str_replace('//', '/', self::$routes);

        $foundRoute = false;

        // Parse query parameters
        {
            $query = '';
            $q_arr = array();
            if (strpos($uri, '&') > 0) {
                $query = substr($uri, strpos($uri, '&') + 1);
                $uri = substr($uri, 0, strpos($uri, '&'));
                $q_arr = explode('&', $query);
                foreach ($q_arr as $q) {
                    $qobj = explode('=', $q);
                    $q_arr[] = array($qobj[0] => $qobj[1]);
                    if (!isset($_GET[$qobj[0]])) {
                        $_GET[$qobj[0]] = $qobj[1];
                    }
                }
            }
        }

        // Check if route is defined without regex

        if (in_array($uri, self::$routes)) {

            $routePos = array_keys(self::$routes, $uri);

            // Foreach route position
            foreach ($routePos as $route) {

                if (self::$methods[$route] == $method || self::$methods[$route] == 'ANY') {
                    $foundRoute = true;

                    // If route is not an object

                    if (!is_object(self::$callbacks[$route])) {

                        // Call object controller and method

                        self::invokeObject(self::$callbacks[$route]);
                        if (self::$halts) return;

                    } else {

                        // Call closure

                        call_user_func(self::$callbacks[$route]);
                        if (self::$halts) return;

                    }
                }

            }

        } else {

            // Check if defined with regex
            $pos = 0;

            // Foreach routes

            foreach (self::$routes as $route) {

                $route = str_replace('//', '/', $route);

                if (strpos($route, ':') !== false) {
                    $route = str_replace($searches, $replaces, $route);
                }

                if (preg_match('#^' . $route . '$#', $uri, $matched)) {

                    if (self::$methods[$pos] == $method || self::$methods[$pos] == 'ANY') {
                        $foundRoute = true;

                        // Remove $matched[0] as [1] is the first parameter.

                        array_shift($matched);

                        if (!is_object(self::$callbacks[$pos])) {

                            // Call object controller and method

                            self::invokeObject(self::$callbacks[$pos], $matched);
                            if (self::$halts) return;

                        } else {

                            // Call closure
                            call_user_func_array(self::$callbacks[$pos], $matched);
                            if (self::$halts) return;

                        }
                    }
                }

                $pos++;
            }
        }

        // Run the error callback if the route was not found

        if (!$foundRoute) {

            if (!self::$errorCallback) {

                self::$errorCallback = function () {
                    header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found");
                    echo '404';
                };
            }

            if (!is_object(self::$errorCallback)) {

                // Call object controller and method
                self::invokeObject(self::$errorCallback, null, 'No routes found.');
                if (self::$halts) return;

            } else {

                call_user_func(self::$errorCallback);
                if (self::$halts) return;

            }
        }
    }
218256
private function invokeHandler($isCli, $handlerParams)
    {
        $activeHandler = null;
        try {
            // determine which handler should handle this path
            $activeHandler = $this->determineHandler($isCli, $handlerParams);
            $this->logger->debug("SnappyRouter: Selected handler: " . get_class($activeHandler));
            // invoke the initial plugin hook
            $activeHandler->invokePluginsHook(
                'afterHandlerSelected',
                array($activeHandler)
            );
            $this->logger->debug("SnappyRouter: routing");
            $response = $activeHandler->performRoute();
            $activeHandler->invokePluginsHook(
                'afterFullRouteInvoked',
                array($activeHandler)
            );
            return $response;
        } catch (Exception $e) {
            return $this->handleInvocationException($e, $activeHandler, $isCli);
        }
    }
30755
public function invoke(MethodInvocation $invocation)
    {
        /** @var \Ytake\LaravelAspect\Annotation\QueryLog $annotation */
        $annotation = $invocation->getMethod()->getAnnotation($this->annotation);
        $this->subscribeQueryLog();
        $result = $invocation->proceed();
        $logFormat = $this->queryLogFormatter($annotation, $invocation);
        $logger = static::$logger;
        if ($logger instanceof LogManager) {
            if (!is_null($annotation->driver)) {
                $logger = $logger->driver($annotation->driver);
            }
            $logger->addRecord($logFormat['level'], $logFormat['message'], $logFormat['context']);
        }
        $this->queryLogs = [];

        return $result;
    }
766487
public function dispatch($method, $params)
    {
        // find() and all() are aliases
        if (($method == 'find' && empty($params)) || $method == 'all') {
            return $this->find();
        }

        // handle find or one with sql params
        else if (($method == 'find' || $method == 'one') && is_string($params[0])) {
            $rs = $this->find(new Criteria(array_shift($params), $params));

            return $method == 'one' ? $rs->one() : $rs;
        }

        // handle magical finders
        else if (preg_match('/^(findBy|oneBy)/', $method)) {
            $rs = $this->find(new Criteria($this->_sqlFromMethod($method), $params));

            return preg_match('/^(oneBy)/', $method) ? $rs->one() : $rs;
        }

        // handle byId
        else if ($method == 'byId') {
            return $this->_findById($params);
        }

        // Criteria search
        else if (isset($params[0]) && $params[0] instanceof Criteria) {
            return $this->find($params[0]);
        }

        // failed to wizard :(
        else {
            throw new \BadMethodCallException("Unable to dispatch '$method' to finder");
        }
    }
804907
protected function dispatchProcess(Request $request, Response $response)
    {
        if ($request->getController() === null || $request->getAction() === null) {
            throw new ArchException('Controller or action not defined. Router problem?');
        }
        $actionMethod = $request->getAction() . 'Action';
        ob_start();
        $this->dispatched = true;
        $controllerName = $request->getController();
        if (!$controllerName) {
            throw new ArchException('Controller is undefined');
        }
        $controller = Container::getController($controllerName);
        if (!($controller instanceof \Osf\Controller\Action)) {
            throw new ArchException('Your controller class for application ' . $request->getController() . ' must extends \Osf\Controller\Action');
        }
        if (!method_exists($controller, $actionMethod)) {
            throw new HttpException('Action ' . $actionMethod . '() not found in controller class of application ' . $request->getController(), 404);
        }
        if ($this->dispatched) {
            $controller->preDispatch();
            self::debug('Call ' . $controllerName . '::' . $actionMethod . '()');
            $viewParams = $controller->$actionMethod();
            $controller->postDispatch();
            $content = ob_get_clean();
            $content && $response->appendBody($content);
            if ($viewParams === null) {
                $viewParams = [];
            } elseif (!is_array($viewParams)) {
                throw new ArchException('Action must return an array or null');
            }
        } else {
            self::debug('No call of ' . $controllerName . '::' . $actionMethod . '(), not dispatched');
            ob_clean();
        }
        if ($this->dispatched && $this->renderView) {
            $response->appendBody(Container::getView()->register($viewParams)->render());
        }

        return $this;
    }
155171
public function dispatch($event, array $param = [])
    {
        foreach ($this->listeners[$event] as $listener) {
            \call_user_func_array($listener, $param);
        }
    }
940641
function invoke() {
        parent::invoke();

        $result = true;

        // Set own core attributes
        $this->does_generate = ACTION_GENERATE_XML;

        // These are always here
        global $CFG, $XMLDB;

        // Do the job, setting result as needed

        // Get the file parameter
        $file = required_param('file', PARAM_PATH);
        $file = $CFG->dirroot . $file;
        // File must be under $CFG->wwwroot and
        // under one db directory (simple protection)
        if (substr($file, 0, strlen($CFG->dirroot)) == $CFG->dirroot &&
            substr(dirname($file), -2, 2) == 'db') {
            // Everything is ok. Load the file to memory
            $this->output = file_get_contents($file);
        } else {
            // Switch to HTML and error
            $this->does_generate = ACTION_GENERATE_HTML;
            $this->errormsg = 'File not viewable (' . $file .')';
            $result = false;
        }

        // Return ok if arrived here
        return $result;
    }