PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
5.12.1 5.12.0 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 / FragmentUriGenerator.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
FragmentUriGenerator.php
81 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\RequestStack;
15 use Matomo\Dependencies\Symfony\Component\HttpKernel\Controller\ControllerReference;
16 use Matomo\Dependencies\Symfony\Component\HttpKernel\UriSigner;
17 /**
18 * Generates a fragment URI.
19 *
20 * @author Kévin Dunglas <kevin@dunglas.fr>
21 * @author Fabien Potencier <fabien@symfony.com>
22 */
23 final class FragmentUriGenerator implements FragmentUriGeneratorInterface
24 {
25 private $fragmentPath;
26 private $signer;
27 private $requestStack;
28 public function __construct(string $fragmentPath, ?UriSigner $signer = null, ?RequestStack $requestStack = null)
29 {
30 $this->fragmentPath = $fragmentPath;
31 $this->signer = $signer;
32 $this->requestStack = $requestStack;
33 }
34 /**
35 * {@inheritDoc}
36 */
37 public function generate(ControllerReference $controller, ?Request $request = null, bool $absolute = \false, bool $strict = \true, bool $sign = \true) : string
38 {
39 if (null === $request && (null === $this->requestStack || null === ($request = $this->requestStack->getCurrentRequest()))) {
40 throw new \LogicException('Generating a fragment URL can only be done when handling a Request.');
41 }
42 if ($sign && null === $this->signer) {
43 throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
44 }
45 if ($strict) {
46 $this->checkNonScalar($controller->attributes);
47 }
48 // We need to forward the current _format and _locale values as we don't have
49 // a proper routing pattern to do the job for us.
50 // This makes things inconsistent if you switch from rendering a controller
51 // to rendering a route if the route pattern does not contain the special
52 // _format and _locale placeholders.
53 if (!isset($controller->attributes['_format'])) {
54 $controller->attributes['_format'] = $request->getRequestFormat();
55 }
56 if (!isset($controller->attributes['_locale'])) {
57 $controller->attributes['_locale'] = $request->getLocale();
58 }
59 $controller->attributes['_controller'] = $controller->controller;
60 $controller->query['_path'] = http_build_query($controller->attributes, '', '&');
61 $path = $this->fragmentPath . '?' . http_build_query($controller->query, '', '&');
62 // we need to sign the absolute URI, but want to return the path only.
63 $fragmentUri = $sign || $absolute ? $request->getUriForPath($path) : $request->getBaseUrl() . $path;
64 if (!$sign) {
65 return $fragmentUri;
66 }
67 $fragmentUri = $this->signer->sign($fragmentUri);
68 return $absolute ? $fragmentUri : substr($fragmentUri, \strlen($request->getSchemeAndHttpHost()));
69 }
70 private function checkNonScalar(array $values) : void
71 {
72 foreach ($values as $key => $value) {
73 if (\is_array($value)) {
74 $this->checkNonScalar($value);
75 } elseif (!\is_scalar($value) && null !== $value) {
76 throw new \LogicException(sprintf('Controller attributes cannot contain non-scalar/non-null values (value for key "%s" is not a scalar or null).', $key));
77 }
78 }
79 }
80 }
81