Dispatch request

@return \Magento\Framework\Controller\ResultInterface|ResponseInterface
@throws \Magento\Framework\Exception\NotFoundException
435598
public function execute()
    {
        $id = $this->getRequest()->getParam('id');
        if ($id) {
            $menu = $this->menuRepository->getById($id);
        } else {
            $menu = $this->menuFactory->create();
        }
        $menu->setTitle($this->getRequest()->getParam('title'));
        $menu->setIdentifier($this->getRequest()->getParam('identifier'));
        $menu->setCssClass($this->getRequest()->getParam('css_class'));
        $menu->setIsActive(1);
        $menu = $this->menuRepository->save($menu);

        if (!$id) {
            $id = $menu->getId();
        }

        $menu->saveStores($this->getRequest()->getParam('stores'));

        $nodes = $this->getRequest()->getParam('serialized_nodes');
        if (!empty($nodes)) {
            $nodes = json_decode($nodes, true);
            $nodes = $this->_convertTree($nodes, '#');

            if (!empty($nodes)) {

                $filterBuilder = $this->filterBuilderFactory->create();
                $filter = $filterBuilder->setField('menu_id')->setValue($id)->setConditionType('eq')->create();

                $filterGroupBuilder = $this->filterGroupBuilderFactory->create();
                $filterGroup = $filterGroupBuilder->addFilter($filter)->create();

                $searchCriteriaBuilder = $this->searchCriteriaBuilderFactory->create();
                $searchCriteria = $searchCriteriaBuilder->setFilterGroups([$filterGroup])->create();

                $oldNodes = $this->nodeRepository->getList($searchCriteria)->getItems();

                $existingNodes = [];
                foreach ($oldNodes as $node) {
                    $existingNodes[$node->getId()] = $node;
                }

                $nodesToDelete = [];
                foreach ($existingNodes as $nodeId => $noe) {
                    $nodesToDelete[$nodeId] = true;
                }

                $nodeMap = [];

                foreach ($nodes as $node) {
                    $nodeId = $node['id'];
                    $matches = [];
                    if (preg_match('/^node_([0-9]+)$/', $nodeId, $matches)) {
                        $nodeId = $matches[1];
                        unset($nodesToDelete[$nodeId]);
                        $nodeMap[$node['id']] = $existingNodes[$nodeId];
                    } else {
                        $nodeObject = $this->nodeFactory->create();
                        $nodeObject->setMenuId($id);
                        $nodeObject = $this->nodeRepository->save($nodeObject);
                        $nodeMap[$nodeId] = $nodeObject;
                    }
                }

                foreach (array_keys($nodesToDelete) as $nodeId) {
                    $this->nodeRepository->deleteById($nodeId);
                }

                $path = [
                    '#' => 0,
                ];
                foreach ($nodes as $node) {
                    if ($node['type'] == 'product' && !$this->validateProductNode($node)) {
                        continue;
                    }
                    $nodeObject = $nodeMap[$node['id']];

                    $parents = array_keys($path);
                    $parent = array_pop($parents);
                    while ($parent != $node['parent']) {
                        array_pop($path);
                        $parent = array_pop($parents);
                    }

                    $level = count($path) - 1;
                    $position = $path[$node['parent']]++;

                    if ($node['parent'] == '#') {
                        $nodeObject->setParentId(null);
                    } else {
                        $nodeObject->setParentId($nodeMap[$node['parent']]->getId());
                    }

                    $nodeObject->setType($node['type']);
                    if (isset($node['classes'])) {
                        $nodeObject->setClasses($node['classes']);
                    }
                    if (isset($node['content'])) {
                        $nodeObject->setContent($node['content']);
                    }
                    if (isset($node['target'])) {
                        $nodeObject->setTarget($node['target']);
                    }
                    $nodeObject->setMenuId($id);
                    $nodeObject->setTitle($node['title']);
                    $nodeObject->setIsActive(1);
                    $nodeObject->setLevel($level);
                    $nodeObject->setPosition($position);

                    $this->nodeRepository->save($nodeObject);

                    $path[$node['id']] = 0;
                }
            }
        }

        $redirect = $this->resultRedirectFactory->create();
        $redirect->setPath('*/*/index');

        if ($this->getRequest()->getParam('back')) {
            $redirect->setPath('*/*/edit', ['id' => $menu->getId(), '_current' => true]);
        }

        return $redirect;
    }
1159338
public function dispatch()
    {
		/**
         * Calling before dispatch listener
         */
		if ( is_object($this->_events_manager) )
        {
            $this->_events_manager->fire( "dispatch:beforeDispatch", $this );
		}

		$finished = false;

		$number_dispatches = 0;

		while ( !$finished )
		{
			$number_dispatches++;

			if ( $number_dispatches == 100 )
            {
                $this->_throwDispatchException( "Dispatch error. Cyclic routing.", self::EXCEPTION_CYCLIC_ROUTING );
				break;
			}

            $controller_name = $this->_route->getControllerName();
            $action_name     = $this->_route->getActionName();
            $params          = $this->_route->getParams();

            if ( !class_exists($controller_name) )
            {
                if ( $this->_throwDispatchException( $controller_name . " controller class cannot be loaded.", self::EXCEPTION_CONTROLLER_NOT_FOUND ) == false )
                {
                    continue;
                }

                break;
            }

            $controller_instance = new $controller_name();

            if ( !method_exists($controller_instance, $action_name) )
            {
                if ( $this->_throwDispatchException( $action_name . "Action action does not exist in " . $controller_name . ".", self::EXCEPTION_ACTION_NOT_FOUND ) == false )
                {
                    continue;
                }

                break;
            }

            /**
             * Calling before execute route listener
             */
            if ( is_object($this->_events_manager) )
            {
                $this->_events_manager->fire( "dispatch:beforeExecuteRoute", $this );

                /**
                 * If there was a forward in the listener
                 */
                if ( $this->_was_forwarded )
                {
                    $this->_was_forwarded = false;
                    continue;
                }
            }

            $controller_instance->setDI( $this->_di );

            $controller_instance->initialize();

			/**
             * Calling action in controller with params
             */
            call_user_func_array( array($controller_instance, $action_name), $params );

			/**
             * If there was a forward in the action
             */
			if ( $this->_was_forwarded )
            {
				$this->_was_forwarded = false;
				continue;
			}

			$finished = true;
		}
    }
1014461
public function dispatch(ServerRequestInterface $request): ResponseInterface
    {
        $resolved = $this->resolve(0);

        return $resolved->handle($request);
    }
1281227
public function dispatch()
    {
        Eresus_Kernel::app()->getEventDispatcher()->dispatch('cms.admin.start');

        if (!UserRights(EDITOR))
        {
            $response = $this->authAction();
        }
        else
        {
            /** @var TAdminUI|TClientUI $page */
            $page = $this->getPage();
            $response = $page->render($this->getRequest());
        }
        return $response;
    }
284470
public static function dispatch()
    {
        if (self::$force) {
            return null;
        }

        self::forceRender();

        if (self::$views) {
            foreach (self::$views as &$value) {
                $value && self::render($value[0], $value[1]);
            }
        }
    }
1324585
public function getDispatchAction()
    {
        $params = $this->request->getAll();
        foreach (array_keys($params) as $key) {
            if (preg_match('/^dispatch-(.+)/', $key, $matches)) {
                $action = str_replace('-', '.', $matches[1]);
                return $action;
            }
        }
    }
758550
public function run(): Response
    {
        try {
            $response = $this->dispatch();
            $this->send($response);
        } catch (\Error $e) {
            $response = $this->exceptionHandler->handleError($e);
            $this->send($response);
        } catch (\Exception $e) {
            $response = $this->exceptionHandler->handleException($e);
            $this->send($response);
        }

        return $response;
    }
560864
public static function dispatch()
    {
        $vars = [];

        $request = Request::createFromGlobals();

        $dispatcher = new Dispatcher(static::instance()->getData());
        $routeInfo = $dispatcher->dispatch(
            $request->getMethod(),
            $request->getUri()->getPath()
        );

        $controller = "\\Barebone\\Controller";
        $action = "index";

        switch ($routeInfo[0]) {
        case Dispatcher::NOT_FOUND:
            $action = 'routerError';
            $vars['error'] = static::ERR_NOT_FOUND;
            $vars['subject'] = $request->getUri()->getPath();
            break;

        case Dispatcher::METHOD_NOT_ALLOWED:
            $action = 'routerError';
            $vars['error'] = static::ERR_BAD_METHOD;
            $vars['subject'] = $routeInfo[1];
            break;

        case Dispatcher::FOUND:
            $handler = $routeInfo[1];
            $vars = $routeInfo[2];

            if (!class_exists($handler[0])) {
                $action = 'routerError';
                $vars['error'] = static::ERR_MISSING_CONTROLLER;
                $vars['subject'] = $handler[0];
            } elseif (!method_exists($handler[0], $handler[1])) {
                $action = 'routerError';
                $vars['error'] = static::ERR_MISSING_ACTION;
                $vars['subject'] = $handler[0] . '::' . $handler[1];
            } else {
                $controller = $handler[0];
                $action = $handler[1];
            }
            break;
        }

        // Start with an empty response
        $response = new Response();
        $request->setAction($action);

        // @var Controller $instance
        $instance = new $controller($request, $response);
        $instance->initController();

        // Get Middleware stacks
        $before = $instance->getMiddlewareBefore();
        $after = $instance->getMiddlewareAfter();

        // Append the action call to the middleware stack
        $before[] = function (Request $request, Response $response,
            callable $next = null
        ) use ($instance, $action, $vars) {

            // assigned updated objects
            $instance->setRequest($request);
            $instance->setResponse($response);

            // get updated response from action
            $response = call_user_func_array([$instance, $action], $vars);

            // continue
            return $next($instance->getRequest(), $response);
        };

        // Run the middleware stack and return the Response
        $middlewares = array_reverse(array_merge($before, $after));
        $runner = \Sirius\Middleware\Runner::factory($middlewares);

        return $runner($request, $response);
    }
684239
public function dispatch()
    {
        foreach ($this->middleware as $mw) {
            call_user_func_array($mw, array($this));
        }

        $return = call_user_func_array($this->getCallable(), array_values($this->getParams()));
        return ($return === false) ? false : true;
    }
626247
public function dispatch() {
		$url  = add_query_arg( $this->get_query_args(), $this->get_query_url() );
		$args = $this->get_post_args();

		Logger::info( "Background dispatching $url", $args);

		$rawUrl = esc_url_raw( $url );
		Logger::info("Async call to $rawUrl", ['args' => $args]);
		$result = wp_remote_post( $rawUrl, $args );
		Logger::info("Async call complete.", ['url' => $rawUrl, 'result'=>$result]);
		return $result;
	}
1156312
public function getRequest()
    {
        if(!$this->_request instanceof DispatcherRequestInterface) {
            $this->_request = clone $this->getObject('dispatcher.request');
        }

        return $this->_request;
    }
881022
public function dispatch(Request $request)
    {
        $this->validate($request);

        return $this->next->dispatch($request);
    }
190168
protected function dispatch()
    {
        // Start processing the requests.
        list($mrc, $active) = $this->process();

        // Keep processing requests until we're done.
        while ($active and $mrc === CURLM_OK) {
            // Process the next request.
            list($mrc, $active) = $this->process();
        }

        // Throw an exception if something went wrong.
        if ($mrc !== CURLM_OK) {
            throw new CurlErrorException('cURL read error #'.$mrc);
        }
    }
1331295
public function getRequest()
    {
        if(!$this->_request instanceof DispatcherRequestInterface)
        {
            //Setup the request
            $this->_request->user = $this->getUser();

            $this->_request = $this->getObject('dispatcher.request', ObjectConfig::unbox($this->_request));

            if(!$this->_request instanceof DispatcherRequestInterface)
            {
                throw new \UnexpectedValueException(
                    'Request: '.get_class($this->_request).' does not implement DispatcherRequestInterface'
                );
            }
        }

        return $this->_request;
    }
121580
public function dispatch(Request $request)
    {
        $url = $request->getQueryString();
        $url = $this->RemoveQueryString($url, new Request());
        if ($this->match($url)) {
            (isset($this->params['middleware'])) ? $this->params['middleware'] = new $this->params['middleware']() : null;
            if (!isset($this->params['callable'])) {
                $controller = $this->params['controller'];
                $controller = $this->convertToStudlyCaps($controller);
                $controller = $this->getNamespace().$controller;
                if (class_exists($controller)) {
                    (isset($this->params['middleware']) && is_object($this->params['middleware'])) ? ( new $this->params['middleware']())->before(new Request(), new Response(), $this->params) : null;
                    $controller_object = new $controller($this->params, $this->getInput(new Input()));
                    $action = $this->params['action'];
                    $action = $this->convertToCamelCase($action);
                    if (preg_match('/action$/i', $action) == 0) {
                        $controller_object->$action();
                        (isset($this->params['middleware']) && is_object($this->params['middleware'])) ? (new $this->params['middleware']())->after(new Request(), new Response(), $this->params) : null;
                    } else {
                        throw new \Exception("Method $action in controller $controller cannot be called directly - remove the Action suffix to call this method");
                    }
                } else {
                    throw new \Exception("Controller class $controller not found");
                }
            } else {
                (is_object(isset($this->params['middleware']))) ? $this->params['middleware']->before(new Request(), new Response(), $this->params) : null;
                call_user_func($this->params['callable'], $this->params);
                (is_object(isset($this->params['middleware']))) ? $this->params['middleware']->after(new Request(), new Response(), $this->params) : null;
            }
        } else {
            View::view('errors/404', [], true, [], 404);
        }
    }
198673
public function dispatch(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
        {
            reset($this->middleware);
            $this->response = $response;
            return $this->handle($request);
        }
469200
public function getResponse()
    {
        $this->matcher = new UrlMatcher($this->routes, $this->context);

        $this->parameters = $this->matcher->matchRequest($this->request);

        $controller = $this->parameters['_controller'];
        if ($controller === null) {
            $response = new Response();
        } else {
            $this->controller = new $controller($this->request, $this->parameters);
            $response = $this->controller->handler();
        }

        return $response;
    }