getScriptResponse example

/** @var StoreApiResponseHook $responseHook */
        $responseHook = $hook->getFunction(StoreApiResponseHook::FUNCTION_NAME);
        // hook: store-api-{hook}         $this->executor->execute($responseHook);

        $fields = new ResponseFields(
            $request->get('includes', [])
        );

        $symfonyResponse = $this->scriptResponseEncoder->encodeToSymfonyResponse(
            $responseHook->getScriptResponse(),
            $fields,
            \str_replace('-', '_', 'store_api_' . $hookName . '_response')
        );

        $cacheConfig = $responseHook->getScriptResponse()->getCache();
        if ($cacheKey && $cacheConfig->isEnabled()) {
            $this->storeResponse($cacheKey$cacheConfig$symfonyResponse);
        }

        return $symfonyResponse;
    }

    
$page = $this->pageLoader->load($request$context);

        $hook = new StorefrontHook($hookName$request->request->all()$request->query->all()$page$context);

        // hook: storefront-{hook}         $this->hook($hook);

        $fields = new ResponseFields(
            $request->get('includes', [])
        );

        $response = $hook->getScriptResponse();

        $symfonyResponse = $this->scriptResponseEncoder->encodeToSymfonyResponse(
            $response,
            $fields,
            \str_replace('-', '_', 'storefront_' . $hookName . '_response')
        );

        if ($response->getCache()->isEnabled()) {
            $request->attributes->set(PlatformRequest::ATTRIBUTE_HTTP_CACHE, ['maxAge' => $response->getCache()->getMaxAge(), 'states' => $response->getCache()->getInvalidationStates()]);
            $symfonyResponse->headers->set(CacheStore::TAG_HEADER, \json_encode($response->getCache()->getCacheTags(), \JSON_THROW_ON_ERROR));
        }

        
$this->validate($instance$context);

        // hook: api-{hook}         $this->executor->execute($instance);

        $fields = new ResponseFields(
            $request->get('includes', [])
        );

        return $this->scriptResponseEncoder->encodeToSymfonyResponse(
            $instance->getScriptResponse(),
            $fields,
            \str_replace('-', '_', 'api_' . $hook . '_response')
        );
    }

    private function validate(ApiHook $hook, Context $context): void
    {
        $scripts = $this->loader->get($hook->getName());

        /** @var Script $script */
        foreach ($scripts as $script) {
            
Home | Imprint | This part of the site doesn't use cookies.