Execute interceptor

@access private
@param string $type
@param object $request
@param object $response
@return bool
340188
private function executeInterceptor($type, Request $request, Response $response) {
		foreach ($this->interceptor[$type] as $it) {
			if (isset($it['all'])) {
				if ($it['handler']->{$type}($request, $response) !== null) {
					return true;
				}
			} elseif (isset($it['uri'])) {
				if ($request->uri === $it['uri']) {
					if ($it['handler']->{$type}($request, $response) !== null) {
						return true;
					}
				}
			} else {
				if (preg_match($it['regex'], $request->uri)) {
					if ($it['handler']->{$type}($request, $response) !== null) {
						return true;
					}
				}
			}
		}
		return null;
	}
170255
public function execute(ServerRequestInterface $request, ResponseInterface $response) : ResponseInterface {
		$httpRequestResponse = new HTTPRequestResponseContainer($request, $response);

		$this->dispatchRequestFilters($httpRequestResponse);

		$this->dispatchResponseFilters($httpRequestResponse);

		return $httpRequestResponse->getResponse();
	}
1081428
private function send(Response $response, $type = self::MASTER_REQUEST)
    {
        if (null !== $this->application && null !== $this->application->getEventDispatcher()) {
            $event = new FilterResponseEvent($this, $this->getRequest(), $type, $response);
            $this->application->getEventDispatcher()->dispatch('frontcontroller.response', $event);
            $this->application->getEventDispatcher()->dispatch(KernelEvents::RESPONSE, $event);
        }

        $response->send();
        $this->response = $response;
        $this->application->stop();
    }
486496
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
	{
		$this->checkRequestForArraySessions($request);

		// If a session driver has been configured, we will need to start the session here
		// so that the data is ready for an application. Note that the FlyPHP sessions
		// do not make use of PHP "native" sessions in any way since they are crappy.
		if ($this->sessionConfigured())
		{
			$session = $this->startSession($request);

			$request->setSession($session);
		}

		$response = $this->app->handle($request, $type, $catch);

		// Again, if the session has been configured we will need to close out the session
		// so that the attributes may be persisted to some storage medium. We will also
		// add the session identifier cookie to the application response headers now.
		if ($this->sessionConfigured())
		{
			$this->closeSession($session);

			$this->addCookieToResponse($response, $session);
		}

		return $response;
	}
1051400
private function executePreInterceptor($preInterceptor, Request $request, Response $response)
    {
        if (is_callable($preInterceptor)) {
            return $preInterceptor($request, $response);
        }

        if ($preInterceptor instanceof PreInterceptor) {
            return $preInterceptor->preProcess($request, $response);
        }

        $instance = $this->injector->getInstance($preInterceptor);
        if (!($instance instanceof PreInterceptor)) {
            $response->write(
                    $response->internalServerError(
                            'Configured pre interceptor ' . $preInterceptor
                            . ' is not an instance of ' . PreInterceptor::class
                    )
            );
            return false;
        }

        return $instance->preProcess($request, $response);
    }
1048290
public function check(Request $request, Response $response) {
        $actual = $request->getStage('csrf');
        $expected = $request->getSession('csrf');

        //no longer needed
        $request->removeSession('csrf');

        if($actual !== $expected) {
            //prepare to error
            $message = $this->app->package('global')->translate(static::ATTACK);
            $response->setError(true, $message);

            //and trigger a subflow
            $this->app->subflow($this->no, $request, $response);
            return $this;
        }

        //it passed
        $this->app->subflow($this->yes, $request, $response);
        return $this;
    }
76965
public function handle(
        ServerRequestInterface $request, ResponseInterface $response
    )
    {
        $route = $this->getMatcher()->match($request);
        $request = $request->withAttribute('route', $route);
        return $this->executeNext($request, $response);
    }
1157045
public function run(ServerRequestInterface $request, ResponseInterface $response)
    {
        $route = $request->getAttribute('route');        
        $name = !empty($route->controller) ? $route->controller : 'default';
        
        try {
            $controller = call_user_func($this->getFactory(), $name);
        } catch (\Exception $ex) {
            trigger_error($ex->getMessage(), E_USER_NOTICE);
            return $this->notFound($request, $response);
        }

        if (!method_exists($controller, '__invoke')) {
            $class = get_class($controller);
            trigger_error("Can't route to controller '$class': class does not have '__invoke' method", E_USER_NOTICE);
            return $this->notFound($request, $response);
        }
        
        return $controller($request, $response);
    }
820089
public function handle(SymfonyRequest $request, $type = self::MASTER_REQUEST, $catch = true)
    {
        try {
            $this->getApplication()->share('request', $request);
            return $this->handleRaw($request, $type);
        } catch (Exception $e) {
            $this->reportException($e);
            $response = $this->renderException($request, $e);
        } catch (Throwable $e) {
            $this->reportException($e = new FatalThrowableError($e));
            $response = $this->renderException($request, $e);
        }
//        event(new Events\RequestHandled($request, $response));
        return $response;
    }
1352418
private function executeCallable($target, RequestInterface $request, ResponseInterface $response)
    {
        ob_start();
        $level = ob_get_level();

        try {
            $arguments = array_merge([$request, $response], $this->arguments);
            $target = self::getCallable($target, $arguments);
            $return = call_user_func_array($target, $arguments);

            if ($return instanceof ResponseInterface) {
                $response = $return;
                $return = '';
            }

            $return = Utils\Helpers::getOutput($level).$return;
            $body = $response->getBody();

            if ($return !== '' && $body->isWritable()) {
                $body->write($return);
            }

            return $response;
        } catch (\Exception $exception) {
            Utils\Helpers::getOutput($level);
            throw $exception;
        }
    }
1374033
public function run(Request $request, Response $response)
    {
        $this->initController($request, $response);
        $event = $this->eventDispatcher->raiseEvent(
            $this->createLoadedEvent()
        );

        if ($event->isHandled() && $event->getResponse() instanceof Response) {
            return $event->getResponse();
        }

        $this->eventDispatcher->raiseEvent(
            $this->createFinishedEvent(
                $this->runController($request, $response)
            )
        );

        return $response;
    }
416423
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
    {
        $filterResponse = new FilterResponse($request);
        $this->eventDispatcher->dispatch(KernelEvents::FILTER_REQUEST, $filterResponse);

        $response = $filterResponse->getResponse();
        if ($response instanceof Response) {
            return $response;
        }

        $controller = $request->attributes->get('_controller');
        if (!$controller) {
            throw new \InvalidArgumentException('Controller is not valid.');
        }

        $action = $request->attributes->get('_action');
        if (!$action) {
            throw new \InvalidArgumentException('Action method is not valid.');
        }

        $request->attributes->remove('_controller');
        $request->attributes->remove('_action');
        $parameters = $request->attributes->get('_parameters', []);
        if (!empty($parameters)) {
            $request->attributes->remove('_parameters');
        }

        $filterController = new FilterController($controller);
        $this->eventDispatcher->dispatch(KernelEvents::FILTER_CONTROLLER, $filterController);

        try {
            $response = call_user_func_array([$controller, $action], array_merge($parameters, [$request]));
        } catch (ResourceNotFoundException $e) {
            $response = new Response('Not found!', Response::HTTP_NOT_FOUND);
        }

        if ($response instanceof Response) {
            $filterResponse->setResponse($response);
            $this->eventDispatcher->dispatch(KernelEvents::FILTER_RESPONSE, $filterResponse);

            return $filterResponse->getResponse();
        }

        throw new \InvalidArgumentException(sprintf('The controller must return a "\Symfony\Component\HttpFoundation\Response" object'));
    }
1203250
public function execute(Framework $framework, WebRequest $request, Response $response)
    {
        // Verify the session
        if (!$request->hasSession() || $request->getRouteParam('token') == '') {
            $response->redirectTo('/');
            return;
        }
        
        $token = $request->getRouteParam('token');
        
        // Verify the datatable session data
        if (!$this->hasValidSessionData($request, $token)) {
            $response->redirectTo('/');
            return;
        }
        
        $class = $request->getSessionData('dt-class-' . $token);
        $time = $request->getSessionData('dt-time-' . $token);
        
        $options = json_decode($request->getSessionData('dt-options-' . $token), true);
        if (!is_array($options)) {
            $options = array();
        }
        
        // Session time expired
        if ($time > time() + 600) {
            $response->redirectTo('/');
            return;
        }
        
        $table = new $class($framework, false);
        $table->setOptions($options);
        $generator = $this->getTableRenderer();
        
        $preparedTable = $generator->prepareTable($request, $table, '');
        $data = array('data' => array());
        foreach ($preparedTable->getBody()->getRows() as $row) {
            $data['data'][] = $row->toArray();
        }
        
        $response->setOutput(json_encode($data));
    }
1247287
public function execute(ServerRequestInterface $request, ResponseInterface $response)
    {
        try {
            return $this->router->start($request, $response);
        } catch (\Exception $e) {
            $this->logger->warning('Unexpected exception: ' . $e->getMessage());
            $this->logger->debug($e->__toString());

            return $response->withStatus(500)
                ->withBody(new StringStream($e->getMessage()));
        }
    }
794688
public function terminate($request, $response)
    {
        if ($this->shouldExecute($request, false)) {
            $this->after($request, $response);
        }

        return;
    }
1034392
public function respond($type = 'json', array $response = array()) {
        if ($response) {
            $response = $response + array(
                'success' => false,
                'data' => '',
                'code' => null
            );

            $this->response($response['success'], $response['data'], $response['code']);
        }

        if ($type === 'html') {
            $this->RequestHandler->renderAs($this->controller, 'ajax');

        } else {
            $this->RequestHandler->respondAs($type);
            $this->controller->autoLayout = false;
            $this->controller->autoRender = false;

            echo $this->_format($type);
        }
    }
1325222
private function intercept(array &$interceptors, &$request, &$method, &$metadata, &$options, callable $callback)
    {
        /** @var Client\Interceptors\Base $i */
        $i = array_shift($interceptors);
        if ($i) {
            $i->setRequest($request);
            $i->setMethod($method);
            $i->setMetadata($metadata);
            $client = $this->getClient();
            $i->setStub($client);
            return $i->call(function () use (
                &$i,
                &$interceptors,
                &$method,
                &$request,
                &$metadata,
                &$options,
                &$callback
            ) {
                $metadata = $i->getMetadata();
                $request = $i->getRequest();
                if (count($interceptors) > 0) {
                    return $this->intercept($interceptors, $request, $method, $metadata, $options, $callback);
                } else {
                    return $callback();
                }
            });
        } else {
            return $callback();
        }
    }