@param BlockContextInterface $blockContext
@param Response              $response

@return Response
186472
protected function createResponse(BlockContextInterface $blockContext, Response $response = null)
    {
        if (null === $response) {
            $response = new Response();
        }

        // set the ttl from the block instance, this can be changed by the BlockService
        if (($ttl = $blockContext->getBlock()->getTtl()) > 0) {
            $response->setTtl($ttl);
        }

        return $response;
    }
37774
private static function stringContainsResourceEntry($blockText,$resource)
		{
			foreach ($resource->resourceContent as $resourceEntry) 
			{
				if(EndBlockFilter::stringContains($blockText,$resourceEntry))
				{
					return true;
				}
			}
			return false;
		}
1029440
private function renderBlock(array $blockNames, $cacheKey, array $context)
    {
        $template = $blockName = null;

        $themes = $this->defaultThemes;
        if (isset($this->themes[$cacheKey])) {
            $themes = array_merge($this->themes[$cacheKey], $this->defaultThemes);
        }

        // Search the template for first block available
        foreach ($blockNames as $name) {
            if ($template = $this->getTemplateForBlock($name, $themes)) {
                $blockName = $name;
                break;
            }
        }

        // Throw if no matching blocks are found
        if (empty($template)) {
            throw new \RuntimeException(sprintf(
                "Block%s %s not found in table themes (%s)",
                count($blockNames) > 1 ? 's' : '', implode(', ', $blockNames), implode(', ', $this->defaultThemes)
            ));
        }

        return $template->renderBlock($blockName, $context);
    }
367922
protected function closeContext(
        Request $request,
        Response $response,
        TokenInterface $token
    ): Response {
        return $token->getOperator()->removeToken($request, $response, $token);
    }
1308629
public function getBlock(?string $blockId = null): GetBlockResponse
    {
        $command = new GetBlockCommand($blockId);
        $response = $this->driver->executeCommand($command);

        return new GetBlockResponse($response->getRawData());
    }
82399
protected function setDefaultExtraCacheKeys(BlockContextInterface $blockContext, array $settings)
    {
        if (!$blockContext->getSetting('use_cache') || $blockContext->getSetting('ttl') <= 0) {
            return;
        }

        $block = $blockContext->getBlock();

        // type by block class
        $class = ClassUtils::getClass($block);
        $cacheServiceId = isset($this->cacheBlocks['by_class'][$class]) ? $this->cacheBlocks['by_class'][$class] : false;

        // type by block service
        if (!$cacheServiceId) {
            $cacheServiceId = isset($this->cacheBlocks['by_type'][$block->getType()]) ? $this->cacheBlocks['by_type'][$block->getType()] : false;
        }

        if (!$cacheServiceId) {
            // no context cache needed
            return;
        }

        // do not add cache settings to extra_cache_keys
        unset($settings['use_cache'], $settings['extra_cache_keys'], $settings['ttl']);

        $extraCacheKeys = $blockContext->getSetting('extra_cache_keys');

        // add context settings to extra_cache_keys
        if (!isset($extraCacheKeys[self::CACHE_KEY])) {
            $extraCacheKeys[self::CACHE_KEY] = $settings;
            $blockContext->setSetting('extra_cache_keys', $extraCacheKeys);
        }
    }
571223
private function getApiResponseContext(RequestContext $requestContext): ResponseContextAbstract
    {
        $responseContext = $this->httpClient->sendRequest(
            $requestContext
        );

        $this->processApiResponseContextErrors($responseContext);

        return $responseContext;
    }
118049
protected function processApiResponseContextErrors(ResponseContextAbstract $responseContext): void
    {
        if ($responseContext->hasHttpError()) {
            throw new BadResponseContextException(
                $responseContext->getHttpStatusMessage(),
                $responseContext->getHttpStatusCode()
            );
        }
    }
1266874
public function getAjaxBlockAction(Request $request, $_ajaxController)
    {
        $response = new Response();
        $response->headers->set('Content-Type', 'application/json');
        try {
            list($controllerParams, $controllerQuery) = $this->getControllerParams($request, $_ajaxController);
            $controllerResponse = $this->forward($_ajaxController, $controllerParams, $controllerQuery);
            $responseContent = array(
                'block' => $controllerResponse->getContent(),
            );
        } catch (AjaxBlocksException $ex) {
            $responseContent = array(
                'error' => array(
                    'code' => $ex->getCode(),
                    'error' => $ex->getMessage(),
                ),
            );
            $response->setStatusCode(406);
        } catch (\Exception $ex) {
            $responseContent = array(
                'error' => array(
                    'code' => AjaxBlocksErrorCodes::UNKNOWN_EXCEPTION,
                    'error' => get_class($ex).'('.$ex->getCode().'): '.$ex->getMessage(),
                ),
            );
            $response->setStatusCode(500);
        }

        $response->setContent(json_encode($responseContent));

        return $response;
    }
249343
public function handle(ServerRequestInterface $request, Response $response)
    {
        $server = $request->getServerParams();
        $server['REQUEST_METHOD'] = $request->getMethod();
        $server['REQUEST_URI'] = $request->getUri()->getPath();
        $globals = [
            '_GET' => $request->getQueryParams(),
            '_POST' => $request->getParsedBody()
        ];
        $req = $this->router->match($globals, $server);
        $resourceObject = $this->resource->{$req->method}->uri($req->path)->withQuery($req->query)->eager->request();
        $response = $this->toPsr7Response($response, $resourceObject);

        return $response;
    }
1030008
public function handle(
        ServerRequestInterface $request, ResponseInterface $response
    )
    {
        $this->request = $request;
        $render = $this->request->getAttribute('render', true);
        if ($render) {
            $response = $this->render($response);
        }
        return $this->executeNext($request, $response);
    }
1021635
public function getResponseFromTemplate($template, $context = [], $response = null)
    {
        if (null === $response) {
            $response = new Response();
        }

        try {
            $html = $this->getTwig()->render($template, $context);
        } catch (\Twig_Error $twigError) {
            if (\PM\Bundle\ToolBundle\Constants\Environment::DEV === $this->getKernelEnvironment()) {
                dump($twigError);
            }

            /* Throw previous if it was a http exception */
            if ($twigError->getPrevious() instanceof HttpException) {
                throw $twigError->getPrevious();
            }

            $html = '<html><body>Unable to render template.</body></html>';
        }

        $response->setContent($html);

        return $response;
    }
113554
public function route(RequestInterface $request, ResponseInterface $response, Context $context = null)
    {
        $this->level++;

        $this->eventDispatcher->dispatch(Event::REQUEST_INCOMING, new RequestIncomingEvent($request));

        // load controller
        if ($context === null) {
            $factory = $this->config->get('psx_context_factory');
            if ($factory instanceof \Closure) {
                $context = $factory();
            } else {
                $context = new Context();
            }
        }

        try {
            $this->loader->load($request, $response, $context);
        } catch (StatusCode\NotModifiedException $e) {
            $response->setStatus($e->getStatusCode());
            $response->setBody(new StringStream());
        } catch (StatusCode\RedirectionException $e) {
            $response->setStatus($e->getStatusCode());
            $response->setHeader('Location', $e->getLocation());
            $response->setBody(new StringStream());
        } catch (\Throwable $e) {
            $this->eventDispatcher->dispatch(Event::EXCEPTION_THROWN, new ExceptionThrownEvent($e, new ControllerContext($request, $response)));

            $this->handleException($e, $response);

            try {
                $context->setException($e);

                $class      = isset($this->config['psx_error_controller']) ? $this->config['psx_error_controller'] : ErrorController::class;
                $controller = $this->controllerFactory->getController($class, $context);

                $this->loader->execute($controller, $request, $response);
            } catch (\Throwable $e) {
                // in this case the error controller has thrown an exception.
                // This can happen i.e. if we can not represent the error in an
                // fitting media type. In this case we send json to the client

                $this->handleException($e, $response);

                $record = $this->exceptionConverter->convert($e);

                $response->setHeader('Content-Type', 'application/json');
                $response->setBody(new StringStream(Parser::encode($record, JSON_PRETTY_PRINT)));
            }
        }

        // for HEAD requests we never return a response body
        if ($request->getMethod() == 'HEAD') {
            $response->setHeader('Content-Length', $response->getBody()->getSize());
            $response->setBody(new StringStream(''));
        }

        $this->eventDispatcher->dispatch(Event::RESPONSE_SEND, new ResponseSendEvent($response));

        $this->level--;

        return $response;
    }
253155
public static BlockCanary install(Context context, BlockCanaryContext blockCanaryContext) {
        BlockCanaryContext.init(context, blockCanaryContext);
        setEnabled(context, DisplayActivity.class, BlockCanaryContext.get().displayNotification());
        return get();
    }
265469
public function checkFieldKey(ServerRequest $request, Response $response): Response
    {
        $queryParams = $request->getQueryParams();
        $fieldKey = $queryParams['key'];
        $table = 'tt_content';
        if (isset($queryParams['table'])) {
            $table = $queryParams['table'];
        }

        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
        $storageRepository = $objectManager->get(StorageRepository::class);

        // check if fieldKey is available for this table
        $isAvailable = true;
        if ($storageRepository->loadField($table, $fieldKey)) {
            $isAvailable = false;
        }

        return new JsonResponse(['isAvailable' => $isAvailable]);
    }
714147
public function execute(BlockInterface $block, Response $response = null, array $parameters = [])
    {
        $this->loadCollection($block);

        return parent::execute($block, $response, $parameters);
    }
596992
private function createBlockInZone(Zone $zone, array $blockData): Block
    {
        $blockCreateStruct = $this->buildBlockCreateStruct($blockData);
        $block = $this->blockService->createBlockInZone($blockCreateStruct, $zone);

        $this->updateBlockTranslations($block, $blockData['parameters']);
        $this->processPlaceholderBlocks($block, $blockData['placeholders']);
        $this->processCollections($block, $blockData['collections']);

        return $block;
    }