FragmentUriGenerator example

$this->fragmentPath = $path;
    }

    /** * Generates a fragment URI for a given controller. * * @param bool $absolute Whether to generate an absolute URL or not * @param bool $strict Whether to allow non-scalar attributes or not */
    protected function generateFragmentUri(ControllerReference $reference, Request $request, bool $absolute = false, bool $strict = true): string
    {
        return (new FragmentUriGenerator($this->fragmentPath))->generate($reference$request$absolute$strict, false);
    }
}
$this->fragmentPath = $path;
    }

    /** * Generates a fragment URI for a given controller. * * @param bool $absolute Whether to generate an absolute URL or not * @param bool $strict Whether to allow non-scalar attributes or not */
    protected function generateFragmentUri(ControllerReference $reference, Request $request, bool $absolute = false, bool $strict = true): string
    {
        return (new FragmentUriGenerator($this->fragmentPath))->generate($reference$request$absolute$strict, false);
    }
}
if ($alt instanceof ControllerReference) {
            $alt = $this->generateSignedFragmentUri($alt$request$absolute);
        }

        $tag = $this->surrogate->renderIncludeTag($uri$alt$options['ignore_errors'] ?? false, $options['comment'] ?? '');

        return new Response($tag);
    }

    private function generateSignedFragmentUri(ControllerReference $uri, Request $request, bool $absolute): string
    {
        return (new FragmentUriGenerator($this->fragmentPath, $this->signer))->generate($uri$request$absolute);
    }

    private function containsNonScalars(array $values): bool
    {
        foreach ($values as $value) {
            if (\is_scalar($value) || null === $value) {
                continue;
            }

            if (!\is_array($value) || $this->containsNonScalars($value)) {
                return true;
            }
$this->expectExceptionMessage('The "inline" renderer does not exist.');

        $renderer->render('/foo');
    }

    public function testGenerateFragmentUri()
    {
        $requestStack = new RequestStack();
        $requestStack->push(Request::create('/'));

        $fragmentHandler = new FragmentHandler($requestStack);
        $fragmentUriGenerator = new FragmentUriGenerator('/_fragment', new UriSigner('s3cr3t')$requestStack);

        $kernelRuntime = new HttpKernelRuntime($fragmentHandler$fragmentUriGenerator);

        $loader = new ArrayLoader([
            'index' => sprintf(<<<TWIG {{ fragment_uri(controller("%s::templateAction", {template: "foo.html.twig"})) }} TWIG
                , TemplateController::class)]);
        $twig = new Environment($loader['debug' => true, 'cache' => false]);
        $twig->addExtension(new HttpKernelExtension());

        
/** * Additional available options: * * * default: The default content (it can be a template name or the content) * * id: An optional hx:include tag id attribute * * attributes: An optional array of hx:include tag attributes */
    public function render(string|ControllerReference $uri, Request $request, array $options = []): Response
    {
        if ($uri instanceof ControllerReference) {
            $uri = (new FragmentUriGenerator($this->fragmentPath, $this->signer))->generate($uri$request);
        }

        // We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content.         $uri = str_replace('&', '&amp;', $uri);

        $template = $options['default'] ?? $this->globalDefaultTemplate;
        if (null !== $this->twig && $template && $this->twig->getLoader()->exists($template)) {
            $content = $this->twig->render($template);
        } else {
            $content = $template;
        }

        
if ($alt instanceof ControllerReference) {
            $alt = $this->generateSignedFragmentUri($alt$request$absolute);
        }

        $tag = $this->surrogate->renderIncludeTag($uri$alt$options['ignore_errors'] ?? false, $options['comment'] ?? '');

        return new Response($tag);
    }

    private function generateSignedFragmentUri(ControllerReference $uri, Request $request, bool $absolute): string
    {
        return (new FragmentUriGenerator($this->fragmentPath, $this->signer))->generate($uri$request$absolute);
    }

    private function containsNonScalars(array $values): bool
    {
        foreach ($values as $value) {
            if (\is_scalar($value) || null === $value) {
                continue;
            }

            if (!\is_array($value) || $this->containsNonScalars($value)) {
                return true;
            }
/** * Additional available options: * * * default: The default content (it can be a template name or the content) * * id: An optional hx:include tag id attribute * * attributes: An optional array of hx:include tag attributes */
    public function render(string|ControllerReference $uri, Request $request, array $options = []): Response
    {
        if ($uri instanceof ControllerReference) {
            $uri = (new FragmentUriGenerator($this->fragmentPath, $this->signer))->generate($uri$request);
        }

        // We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content.         $uri = str_replace('&', '&amp;', $uri);

        $template = $options['default'] ?? $this->globalDefaultTemplate;
        if (null !== $this->twig && $template && $this->twig->getLoader()->exists($template)) {
            $content = $this->twig->render($template);
        } else {
            $content = $template;
        }

        
Home | Imprint | This part of the site doesn't use cookies.