function to dispatch requests coming through the router

@param $action
@param ServerRequestInterface $request
@return ResponseInterface
@throws ActionDoesNotExistException
550268
public function dispatch($action, ServerRequestInterface $request) : ResponseInterface
    {
        $this->getLogger()->debug('dispatching to action: '.$action);
        if (!method_exists($this, $action) && !method_exists($this, '__call')) {
            throw new ActionDoesNotExistException();
        }

        $response = $this->$action($request);
        return $response;
    }
1068465
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $body = $request->getParsedBody();

        $method = strtoupper($body[self::METHOD_INPUT_KEY] ?? $request->getMethod());

        $request = $request->withMethod($method);

        $this->match = $this->adapter->match($request);

        return $this->match->handle($request);
    }
197391
public function dispatch(ServerRequest $request, Response $response)
    {
        if (Router::getRequest(true) !== $request) {
            Router::pushRequest($request);
        }
        $beforeEvent = $this->dispatchEvent('Dispatcher.beforeDispatch', compact('request', 'response'));

        $request = $beforeEvent->getData('request');
        if ($beforeEvent->getResult() instanceof Response) {
            return $beforeEvent->getResult();
        }

        // Use the controller built by an beforeDispatch
        // event handler if there is one.
        if ($beforeEvent->getData('controller') instanceof Controller) {
            $controller = $beforeEvent->getData('controller');
        } else {
            $controller = $this->factory->create($request, $response);
        }

        $response = $this->_invoke($controller);
        if ($request->getParam('return')) {
            return $response;
        }

        $afterEvent = $this->dispatchEvent('Dispatcher.afterDispatch', compact('request', 'response'));

        return $afterEvent->getData('response');
    }
449537
public function dispatch($action = [], $group = null)
    {

        // convert string type to array
        if (is_string($action)) {
            $action = [
                '_controller' => $action
            ];
        }


        // find and register route group
        $this->registerGroup($group, $action);

        // find and run middleware
        if ($middleware = $this->findMiddleware($action)) {
            app()->call([$this, 'middleware'], $middleware);
        }

        if (is_array($action)) {

            list($controller, $method, $namespace) = $this->findControllerAndMethod($action);

            // register the namespace
            isset($namespace) ? $this->setNamespace($namespace) : null;

            // create a controller instance
            $controller = $this->createControllerInstance($controller);

            // call the method
            $response = $this->callControllerMethod($controller, $method);
            return $this->handleResponse($response);

        } elseif ($action instanceof Closure) {
            return $this->handleResponse(app()->call($action, ParameterBag::getParameters()));
        } else {
            return false;
        }
    }
559475
public function get($uri, $action)
    {
        $uri = $this->buildUri($uri);

        return $this->addResponseType(Route::get($uri, $action));
    }
808442
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
    {
        try {
            $endPoint = $this->getPoint($request);
        } catch (\BadMethodCallException $exception) {
            if (!$this->nextOnError) {
                throw $exception;
            }

            return $next->handle($request);
        }

        return $endPoint($request, $next);
    }
318357
public function dispatch(ServerRequestInterface $request)
    {
        $this->finalize();

        $dispatcher = new GroupCountBasedDispatcher($this->getData());
        $uri = '/'.ltrim($request->getUri()->getPath(), '/');

        return $dispatcher->dispatch($request->getMethod(), $uri);
    }
1212009
public function _dispatch($action, $httpMethod, $vars = array())
    {
        $this->_action = $action;
        $this->_data = $_POST;
        $this->_params = array_merge(Atomik::get('request'), $vars);
        $this->_httpMethod = $httpMethod;
        
        $this->preDispatch();
        $result = $this->_execute($action, $this->_params);
        $this->postDispatch($result);
        return $result;
    }
1104085
public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $this->request = $request;
        $response = (new HttpFactory())->createResponse();
        $response = $response->withHeader('Content-Type', 'text/html');
        $pathInfo = RequestHelper::getPathInfo($request);

        try {
            $controller = $this->resolveController($pathInfo);
            $mixed = $this->executeAction($controller);
        } catch (\Throwable $t) {
            // handle errors with built-in error controller
            $controller = new ErrorController($this->view, $request, 'error/error');
            $controller->setError($t);
            $mixed = $this->executeAction($controller);
            $response = $response->withStatus($t->getCode());
        }

        if (is_array($mixed)) {
            $response = $response->withHeader('Content-Type', 'application/json');
            $response->getBody()->write(json_encode($mixed));
        } elseif (is_string($mixed)) {
            $response->getBody()->write($mixed);
        } else {
            throw new \Exception('Unsupported content type');
        }

        return $response;
    }
316197
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');
        $callback = !empty($route->fn) ? $route->fn : null;

        if (!is_callable($callback)) {
            trigger_error("'fn' property of route shoud be a callable", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        return $callback($request, $response);
    }
1044984
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');        
        $file = !empty($route->file) ? ltrim($route->file, '/') : '';

        if ($file[0] === '~' || strpos($file, '..') !== false) {
            trigger_error("Won't route to '$file': '~', '..' are not allowed in filename", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }
        
        if (!file_exists($file)) {
            trigger_error("Failed to route using '$file': File doesn't exist", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        $result = $this->includeScript($file, $request, $response);

        return $result === true || $result === 1 ? $response : $result;
    }
832688
private function dispatch($request, $route)
    {
        if ($route->matched()) {
            $request = $request->withPathToMatch($route->matched(), $route->trailing());
        }
        // dispatch the route!
        return $this->dispatcher->withRoute($route)->__invoke($request);
    }
893484
protected function handleAction($request, $action)
    {
        $classMessage = Director::isLive() ? 'on this handler' : 'on class ' . static::class;

        if (!$this->hasMethod($action)) {
            return new HTTPResponse("Action '$action' isn't available $classMessage.", 404);
        }

        $res = $this->extend('beforeCallActionHandler', $request, $action);
        if ($res) {
            return reset($res);
        }

        $actionRes = $this->$action($request);

        $res = $this->extend('afterCallActionHandler', $request, $action, $actionRes);
        if ($res) {
            return reset($res);
        }

        return $actionRes;
    }
609221
public function auth(Request $request, $action)
    {
        $provider = strtolower($request->attributes->get('provider'));

        if (! $this->providerExists($provider)) {
            return $this->createNotFoundResponse();
        }

        $service = $this->getServiceByProvider($provider);

        $redirectUri = $service->getAuthorizationUri(['state' => $action]);

        $response = new Response();
        $response->setStatusCode(301);
        $response->headers->set('Location', (string) $redirectUri);
        return $response;
    }
672463
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        $this->response = $delegate->process($request);
        $action = $this->action;

        return $action();
    }
74158
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $route = $this->routerDispatcher->dispatch($request);
        if (count($route->getAttributes())) {
            foreach ($route->getAttributes() as $key => $value) {
               $request = $request->withAttribute($key, $value);
            }
        }
        $request = $request->withAttribute('route', $route);

        return $handler->handle($request);
    }
221995
public function mapProviderSave(ServerRequestInterface $request): ResponseInterface
    {
        $provider = $request->getParsedBody()['provider'] ?? '';

        Site::setPreference('map-provider', $provider);

        return redirect(route('admin-control-panel'));
    }