Dispatch request

@return \Magento\Framework\Controller\ResultInterface|ResponseInterface
@throws \Magento\Framework\Exception\NotFoundException
166302
public function execute()
    {
        $id = $this->getRequest()->getParam('id');

        try {
            $menu = $this->menuRepository->getById($id);
            $this->menuRepository->deleteById($id);

            $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();

            $nodes = $this->nodeRepository->getList($searchCriteria);
            foreach ($nodes->getItems() as $node) {
                $this->nodeRepository->delete($node);
            }
            $this->messageManager->addSuccessMessage(__("Menu %1 and it's nodes removed", $menu->getTitle()));
        } catch (CouldNotDeleteException $e) {
            $this->messageManager->addErrorMessage($e->getMessage());
        }

        $redirect = $this->resultRedirectFactory->create();
        $redirect->setPath('*/*/index');
        return $redirect;
    }
72717
public function dispatch(Request $request)
    {
        /** @var DispatcherInterface $dispatcher */
        $dispatcher = $this->make(DispatcherInterface::class);

        return $dispatcher->dispatch($request);
    }
520501
public function dispatch(Request $request)
    {
        $this->currentRequest = $request;
        
        if (is_null($response)) {
            $response = $this->dispatchToRoute($request);
        }
        
        return $this->prepareResponse($request, $response);
    }
895850
public function run()
	{
		// Trigger event!
		$this->dispatch($this->listeners[self::LISTENER_STARTUP], [$this]);

		// Create initial request & response (PSR7!)
		$request = $this->createInitialRequest();
		$response = $this->createInitialResponse();

		try {
			// Trigger event!
			$this->dispatch($this->listeners[self::LISTENER_REQUEST], [$this, $request, $response]);

			// Right to the cycle
			$response = call_user_func(
				$this->chain,
				$request,
				$response,
				function (ServerRequestInterface $request, ResponseInterface $response): ResponseInterface {
					return $response;
				}
			);

			// Response validation check
			if (!isset($response) || $response === null) {
				throw new RuntimeException('Final response cannot be NULL or unset');
			}
		} catch (Throwable $e) {
			// Trigger event! In case of manual handling error, returned object is passed.
			$res = $this->dispatch($this->listeners[self::LISTENER_ERROR], [$this, $e, $request, $response]);
			if ($res !== null && $res !== false) {
				return $res;
			}

			// Throw exception again if it's not caught
			if ($this->catchExceptions !== true) {
				throw $e;
			}
		}

		// Trigger event! In case of manual finalizing, returned object is passed.
		$res = $this->dispatch($this->listeners[self::LISTENER_RESPONSE], [$this, $request, $response]);
		if ($res !== null && $res !== false) {
			return $res;
		}

		// Send to finalizer (simple send response)
		return $this->finalize($request, $response);
	}
1171550
protected function _resolveRequest(DispatcherContext $context)
    {
        //Resolve the controller action
        $method = strtolower($context->request->getMethod());

        if (!in_array($method, $this->getHttpMethods())) {
            throw new DispatcherExceptionMethodNotAllowed('Method '.strtoupper($method).' not allowed');
        }

        $this->setControllerAction($method);

        parent::_resolveRequest($context);
    }
71225
private function _dispatchRequest($request)
	{
		// track the number of requests across instances
		self::$requestCount++;
		$timestart = microtime(true);

		$response = self::transport()->send($request);

		// pass the response through the filter chain
		foreach($this->_filters as $filter)
		{
			$response = $filter->response($response);
		}

		$httpCode = $response->getStatus()->getCode();
		$location = $response->getHeaders()->value('Location');
		$body = $response->getBody();

		// track the time taken across instances
		self::$requestTime += microtime(true) - $timestart;

		// process a redirect if needed
		if($httpCode < 400 && $location)
		{
			return $this->_redirect($location);
		}
		else
		{
			$this->_redirects = 0;
		}

		// translate error code to a typed exception
		if($httpCode == 500)
		{
			throw new Error\InternalServerError($body);
		}
		elseif($httpCode == 400)
		{
			throw new Error\BadRequest($body);
		}
		elseif($httpCode == 401)
		{
			throw new Error\Unauthorized($body);
		}
		elseif($httpCode == 404)
		{
			throw new Error\NotFound($body);
		}
		else if($httpCode >= 300)
		{
			throw new Error($body,$httpCode);
		}

		return $response;
	}
1323128
public static function dispatch() {
        self::$_config = MRest::getConfig('routing');

        $routeData = self::_callDispatcher(self::$_config['dispatcher']);

        if (!class_exists($routeData['class']) || !(new \ReflectionClass($routeData['class']))->isInstantiable()) {
            throw new \Exception('Application class [' . $routeData['class'] . '] was not found', 404);
        }
        $class = new $routeData['class']();

        if (!is_callable([$class, $routeData['method']])) {
            throw new \Exception('Method [' . $routeData['method'] . '] not allowed', 405);
        }

        return call_user_func_array([$class, $routeData['method']], $routeData['attributes']);
    }
1373461
public function sendRequest()
    {
        if ($this->error->hasError() || !$this->http) {
            return;
        }

        if (class_exists($this->dispatcher)) {
            $dispatcherClass = $this->dispatcher;
            $dispatcher = new $dispatcherClass($this->instance->getQuery());
            if ($dispatcher instanceof AbstractDispatcher) {
                $payload = array(
                    'data' => json_encode(array(
                        'config' => $this->config->getRawConfig(),
                        'sql' => $this->instance->getQuery()->toString(),
                        'limit' => $this->instance->getQuery()->getLimit(),
                        'offset' => $this->instance->getQuery()->getOffset(),
                        'single' => $this->instance->getQuery()->isSingle(),
                    )),
                    'key' => $this->key,
                    'method' => $this->method,
                );
                $jsonResult = '[]';

                try {
                    // Guzzle Old
                    if (get_class($this->http) == 'Guzzle\Http\Client') {
                        $request = $this->http->post($this->url, array(), $payload);
                        $response = $request->send();
                        $jsonResult = $response->getBody(true);
                    }
                    // Guzzle 5+
                    elseif (get_class($this->http) == 'GuzzleHttp\Client') {
                        $response = $this->http->request('POST', $this->url, array('form_params' => $payload));
                        $jsonResult = $response->getBody();
                    }
                    // Builtin http client request
                    elseif ($this->http instanceof BuiltinRestClient) {
                        $jsonResult = self::post($this->url, $payload);
                    }

                    if ($this->method == 'getAvailableDrivers') {
                        $this->availableDrivers = json_decode((string) $jsonResult, true);
                    } elseif ($this->method == 'getServerVersion') {
                        $res = json_decode((string) $jsonResult, true);
                        $this->serverVersion = isset($res['version']) ? $res['version'] : null;
                    } else {
                        $dispatcher->dispatch((string) $jsonResult);
                    }
                } catch (\Exception $e) {
                    $this->error->setMessage(strip_tags($e->getMessage()));
                }
            } else {
                $this->error->setMessage(sprintf(
                    'Dispatcher class must be instance of %s, %s given',
                    AbstractDispatcher::class,
                    (string) $this->dispatcher
                ));
            }
        } else {
            $this->error->setMessage(sprintf('Class %s not found', (string) $this->dispatcher));
        }
    }
982827
public function dispatch(Request $request)
    {
        $pathInfo = $request->getPathInfo();
        $method   = $request->getMethod();

        $route = $this->collection->find($method, $pathInfo);

        if ( ! $route) {
            throw new \Exception('Route not found !');
        }

        return $this->dispatcher->dispatch($route);
    }
260611
protected function _run()
    {
//        $class = $this->modelClass;
//        $class::initNavigationPagesById($this->actionParams->get['id']);
        $pageId = \yii::$app->request->getQueryParam('id');
        if ($pageId) {
            $pages = FrontendPage::getNavigationPages($pageId);
            if (empty($pages)) {
                throw new NotFoundHttpException();
            }
        }

        return $this->getResponse([
            'content' => [],
        ]);
    }
808446
public function dispatch()
    {
        if (strtolower(Container::get('config')->get('url_mode')) == 'query_string') {
            $this->uri = explode('?', $this->uri, 2);
            $_SERVER['QUERY_STRING'] = isset($this->uri[1]) ? $this->uri[1] : '';
            $this->uri = $this->uri[0];
            parse_str($_SERVER['QUERY_STRING'], $_GET);
        }

        if ($this->uri == 'favicon.ico') {
            return Container::get('response')->setStatus(404);
        }

        Middleware::register('before_route');
        $parsedRoute = $this->parseRoutes($this->uri);
        Middleware::register('after_route');

        if ($parsedRoute) {
            $this->uri = $parsedRoute;
        } else {
            if (Container::get('request')->isOptions()) {
                Container::get('response')->setStatus(204);
                exit;
            }

            throw new RouteNotFoundException('Request URI ' . $this->uri . ' is not Matched by any route.');
        }

        $this->uris = ($this->uri != '') ? explode('/', trim($this->uri, '/')) : [];

        // Clean uris
        foreach ($this->uris as $key => $value) {
            if ($value == '') {
                unset($this->uris[$key]);
            }
        }

        $this->uris = array_merge($this->uris);

        $this->controller = $this->getController();
        $this->action = $this->getAction();

        // If is already initialized
        $prefix = Container::get('config')->get('namespace_prefix');

        $controllerClassName = $prefix . 'controllers\\' . $this->controller;

        Middleware::register('before_controller');

        if (isset($this->controllers[$this->controller])) {
            $class = $this->controllers[$this->controller];
        } else {
            $constructInstances = $this->getMethodInstances($controllerClassName);
            if (!$constructInstances) {
                $class = new $controllerClassName();
            } else {
                $reflect = new ReflectionClass($controllerClassName);
                $class = $reflect->newInstanceArgs($constructInstances);
            }

            $this->controllers[$this->controller] = $class;
        }

        Middleware::register('after_controller');

        if (!class_exists($controllerClassName)) {
            throw new NotFoundException('Request Controller ' . $this->controller . ' is not Found.');
        }

        if (!method_exists($class, $this->action)) {
            throw new NotFoundException('Request Action ' . $this->action . ' is not Found.');
        }

        $callback = [$class, $this->action];
        if (!is_callable($callback)) {
            throw new NotFoundException($controllerClassName . '::' . $this->action . '() is not callable');
        }

        // Parse params from uri
        $this->params = $this->getParams();

        // Do some final cleaning of the params
        $_GET = array_merge($this->params, $_GET);
        $_REQUEST = array_merge($_POST, $_GET, $_COOKIE);

        if (Container::get('config')->get('app_debug')) {
            Container::get('response')->setHeader('X-Kotori-Hash', call_user_func(function () {
                $lockFile = Helper::getComposerVendorPath() . '/../composer.lock';
                if (!Helper::isFile($lockFile)) {
                    return 'unknown';
                } else {
                    $lockData = file_get_contents($lockFile);
                    $lockData = json_decode($lockData, true);
                    foreach ($lockData['packages'] as $package) {
                        if ($package['name'] == 'kokororin/kotori-php') {
                            return substr($package['source']['reference'], 0, 6);
                        }
                    }
                }

                return 'unknown';
            }));
        }

        Middleware::register('before_action');
        // Call the requested method

        $methodInstances = $this->getMethodInstances($callback[0], $callback[1]);
        if (!$methodInstances) {
            $output = call_user_func_array($callback, $this->params);
        } else {
            $output = call_user_func_array($callback, $methodInstances);
        }

        Middleware::register('after_action');
        if (is_array($output)) {
            Container::get('response')->throwJSON($output);
        }
    }
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);
        }
    }
1022217
protected function dispatchToRouter()
    {
        return function ($request) {
            $this->app->instance('request', $request);

            return $this->router->dispatch($request);
        };
    }
1014203
public function dispatchRequest(ServerRequestInterface $request) : ResponseInterface
    {
        $match = $this->dispatch($request->getMethod(), $request->getUri()->getPath());

        switch ($match[0]) {
            case FastRoute::NOT_FOUND:
                $this->setNotFoundDecoratorMiddleware();
                break;
            case FastRoute::METHOD_NOT_ALLOWED:
                $allowed = (array) $match[1];
                $this->setMethodNotAllowedDecoratorMiddleware($allowed);
                break;
            case FastRoute::FOUND:
                $match[1]->setVars($match[2]);
                $this->setFoundMiddleware($match[1]);
                break;
        }

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

        return $resolved->handle($request);
    }
602092
public function dispatch(ResolvedRequestInterface $resolvedRequest)
    {
        $route = $resolvedRequest->getRoute();
        $controller = $this->container->make($route->getController(), ['resolvedRequest' => $resolvedRequest]);

        // Call the before hook, if defined.
        if (method_exists($controller, 'before')) {
            $this->container->call(
                [$controller, 'before'],
                ['resolvedRequest' => $resolvedRequest] // The resolvedRequest parameter should always receive this.
            );
        }

        // Call the action.
        $response = $this->container->call(
            [$controller, 'action' . $route->getAction()],
            ['resolvedRequest' => $resolvedRequest] // The resolvedRequest parameter should always receive this.
        );

        // Call the after hook, if defined.
        if (method_exists($controller, 'after')) {
            $this->container->call(
                [$controller, 'after'],
                ['resolvedRequest' => $resolvedRequest] // The resolvedRequest parameter should always receive this.
            );
        }

        return $response;
    }
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;
	}