PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / http-kernel / Fragment / HIncludeFragmentRenderer.php
matomo / app / vendor / prefixed / symfony / http-kernel / Fragment Last commit date
AbstractSurrogateFragmentRenderer.php 1 year ago EsiFragmentRenderer.php 2 years ago FragmentHandler.php 1 year ago FragmentRendererInterface.php 2 years ago FragmentUriGenerator.php 1 year ago FragmentUriGeneratorInterface.php 1 year ago HIncludeFragmentRenderer.php 1 year ago InlineFragmentRenderer.php 1 year ago RoutableFragmentRenderer.php 1 year ago SsiFragmentRenderer.php 2 years ago
HIncludeFragmentRenderer.php
91 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace Matomo\Dependencies\Symfony\Component\HttpKernel\Fragment;
12
13 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Request;
14 use Matomo\Dependencies\Symfony\Component\HttpFoundation\Response;
15 use Matomo\Dependencies\Symfony\Component\HttpKernel\Controller\ControllerReference;
16 use Matomo\Dependencies\Symfony\Component\HttpKernel\UriSigner;
17 use Matomo\Dependencies\Twig\Environment;
18 /**
19 * Implements the Hinclude rendering strategy.
20 *
21 * @author Fabien Potencier <fabien@symfony.com>
22 */
23 class HIncludeFragmentRenderer extends RoutableFragmentRenderer
24 {
25 private $globalDefaultTemplate;
26 private $signer;
27 private $twig;
28 private $charset;
29 /**
30 * @param string|null $globalDefaultTemplate The global default content (it can be a template name or the content)
31 */
32 public function __construct(?Environment $twig = null, ?UriSigner $signer = null, ?string $globalDefaultTemplate = null, string $charset = 'utf-8')
33 {
34 $this->twig = $twig;
35 $this->globalDefaultTemplate = $globalDefaultTemplate;
36 $this->signer = $signer;
37 $this->charset = $charset;
38 }
39 /**
40 * Checks if a templating engine has been set.
41 *
42 * @return bool
43 */
44 public function hasTemplating()
45 {
46 return null !== $this->twig;
47 }
48 /**
49 * {@inheritdoc}
50 *
51 * Additional available options:
52 *
53 * * default: The default content (it can be a template name or the content)
54 * * id: An optional hx:include tag id attribute
55 * * attributes: An optional array of hx:include tag attributes
56 */
57 public function render($uri, Request $request, array $options = [])
58 {
59 if ($uri instanceof ControllerReference) {
60 $uri = (new FragmentUriGenerator($this->fragmentPath, $this->signer))->generate($uri, $request);
61 }
62 // We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content.
63 $uri = str_replace('&', '&amp;', $uri);
64 $template = $options['default'] ?? $this->globalDefaultTemplate;
65 if (null !== $this->twig && $template && $this->twig->getLoader()->exists($template)) {
66 $content = $this->twig->render($template);
67 } else {
68 $content = $template;
69 }
70 $attributes = isset($options['attributes']) && \is_array($options['attributes']) ? $options['attributes'] : [];
71 if (isset($options['id']) && $options['id']) {
72 $attributes['id'] = $options['id'];
73 }
74 $renderedAttributes = '';
75 if (\count($attributes) > 0) {
76 $flags = \ENT_QUOTES | \ENT_SUBSTITUTE;
77 foreach ($attributes as $attribute => $value) {
78 $renderedAttributes .= sprintf(' %s="%s"', htmlspecialchars($attribute, $flags, $this->charset, \false), htmlspecialchars($value, $flags, $this->charset, \false));
79 }
80 }
81 return new Response(sprintf('<hx:include src="%s"%s>%s</hx:include>', $uri, $renderedAttributes, $content));
82 }
83 /**
84 * {@inheritdoc}
85 */
86 public function getName()
87 {
88 return 'hinclude';
89 }
90 }
91