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 / AbstractSurrogateFragmentRenderer.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
AbstractSurrogateFragmentRenderer.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\HttpCache\SurrogateInterface;
17 use Matomo\Dependencies\Symfony\Component\HttpKernel\UriSigner;
18 /**
19 * Implements Surrogate rendering strategy.
20 *
21 * @author Fabien Potencier <fabien@symfony.com>
22 */
23 abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRenderer
24 {
25 private $surrogate;
26 private $inlineStrategy;
27 private $signer;
28 /**
29 * The "fallback" strategy when surrogate is not available should always be an
30 * instance of InlineFragmentRenderer.
31 *
32 * @param FragmentRendererInterface $inlineStrategy The inline strategy to use when the surrogate is not supported
33 */
34 public function __construct(?SurrogateInterface $surrogate, FragmentRendererInterface $inlineStrategy, ?UriSigner $signer = null)
35 {
36 $this->surrogate = $surrogate;
37 $this->inlineStrategy = $inlineStrategy;
38 $this->signer = $signer;
39 }
40 /**
41 * {@inheritdoc}
42 *
43 * Note that if the current Request has no surrogate capability, this method
44 * falls back to use the inline rendering strategy.
45 *
46 * Additional available options:
47 *
48 * * alt: an alternative URI to render in case of an error
49 * * comment: a comment to add when returning the surrogate tag
50 *
51 * Note, that not all surrogate strategies support all options. For now
52 * 'alt' and 'comment' are only supported by ESI.
53 *
54 * @see Symfony\Component\HttpKernel\HttpCache\SurrogateInterface
55 */
56 public function render($uri, Request $request, array $options = [])
57 {
58 if (!$this->surrogate || !$this->surrogate->hasSurrogateCapability($request)) {
59 if ($uri instanceof ControllerReference && $this->containsNonScalars($uri->attributes)) {
60 throw new \InvalidArgumentException('Passing non-scalar values as part of URI attributes to the ESI and SSI rendering strategies is not supported. Use a different rendering strategy or pass scalar values.');
61 }
62 return $this->inlineStrategy->render($uri, $request, $options);
63 }
64 if ($uri instanceof ControllerReference) {
65 $uri = $this->generateSignedFragmentUri($uri, $request);
66 }
67 $alt = $options['alt'] ?? null;
68 if ($alt instanceof ControllerReference) {
69 $alt = $this->generateSignedFragmentUri($alt, $request);
70 }
71 $tag = $this->surrogate->renderIncludeTag($uri, $alt, $options['ignore_errors'] ?? \false, $options['comment'] ?? '');
72 return new Response($tag);
73 }
74 private function generateSignedFragmentUri(ControllerReference $uri, Request $request) : string
75 {
76 return (new FragmentUriGenerator($this->fragmentPath, $this->signer))->generate($uri, $request);
77 }
78 private function containsNonScalars(array $values) : bool
79 {
80 foreach ($values as $value) {
81 if (\is_scalar($value) || null === $value) {
82 continue;
83 }
84 if (!\is_array($value) || $this->containsNonScalars($value)) {
85 return \true;
86 }
87 }
88 return \false;
89 }
90 }
91