File manager - Edit - /home/opticamezl/www/newok/web-link.tar
Back
EventListener/AddLinkHeaderListener.php 0000644 00000003043 15173176015 0014177 0 ustar 00 <?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\WebLink\EventListener; use Psr\Link\LinkProviderInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\WebLink\HttpHeaderSerializer; // Help opcache.preload discover always-needed symbols class_exists(HttpHeaderSerializer::class); /** * Adds the Link HTTP header to the response. * * @author Kévin Dunglas <dunglas@gmail.com> * * @final */ class AddLinkHeaderListener implements EventSubscriberInterface { private $serializer; public function __construct() { $this->serializer = new HttpHeaderSerializer(); } public function onKernelResponse(ResponseEvent $event) { if (!$event->isMainRequest()) { return; } $linkProvider = $event->getRequest()->attributes->get('_links'); if (!$linkProvider instanceof LinkProviderInterface || !$links = $linkProvider->getLinks()) { return; } $event->getResponse()->headers->set('Link', $this->serializer->serialize($links), false); } /** * {@inheritdoc} */ public static function getSubscribedEvents(): array { return [KernelEvents::RESPONSE => 'onKernelResponse']; } } Link.php 0000644 00000006507 15173176015 0006170 0 ustar 00 <?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\WebLink; use Psr\Link\EvolvableLinkInterface; class Link implements EvolvableLinkInterface { // Relations defined in https://www.w3.org/TR/html5/links.html#links and applicable on link elements public const REL_ALTERNATE = 'alternate'; public const REL_AUTHOR = 'author'; public const REL_HELP = 'help'; public const REL_ICON = 'icon'; public const REL_LICENSE = 'license'; public const REL_SEARCH = 'search'; public const REL_STYLESHEET = 'stylesheet'; public const REL_NEXT = 'next'; public const REL_PREV = 'prev'; // Relation defined in https://www.w3.org/TR/preload/ public const REL_PRELOAD = 'preload'; // Relations defined in https://www.w3.org/TR/resource-hints/ public const REL_DNS_PREFETCH = 'dns-prefetch'; public const REL_PRECONNECT = 'preconnect'; public const REL_PREFETCH = 'prefetch'; public const REL_PRERENDER = 'prerender'; // Extra relations public const REL_MERCURE = 'mercure'; private $href = ''; /** * @var string[] */ private $rel = []; /** * @var array<string, string|bool|string[]> */ private $attributes = []; public function __construct(string $rel = null, string $href = '') { if (null !== $rel) { $this->rel[$rel] = $rel; } $this->href = $href; } /** * {@inheritdoc} */ public function getHref(): string { return $this->href; } /** * {@inheritdoc} */ public function isTemplated(): bool { return $this->hrefIsTemplated($this->href); } /** * {@inheritdoc} */ public function getRels(): array { return array_values($this->rel); } /** * {@inheritdoc} */ public function getAttributes(): array { return $this->attributes; } /** * {@inheritdoc} * * @return static */ public function withHref($href) { $that = clone $this; $that->href = $href; return $that; } /** * {@inheritdoc} * * @return static */ public function withRel($rel) { $that = clone $this; $that->rel[$rel] = $rel; return $that; } /** * {@inheritdoc} * * @return static */ public function withoutRel($rel) { $that = clone $this; unset($that->rel[$rel]); return $that; } /** * {@inheritdoc} * * @param string|\Stringable|int|float|bool|string[] $value * * @return static */ public function withAttribute($attribute, $value) { $that = clone $this; $that->attributes[$attribute] = $value; return $that; } /** * {@inheritdoc} * * @return static */ public function withoutAttribute($attribute) { $that = clone $this; unset($that->attributes[$attribute]); return $that; } private function hrefIsTemplated(string $href): bool { return str_contains($href, '{') || str_contains($href, '}'); } } GenericLinkProvider.php 0000644 00000003167 15173176015 0011177 0 ustar 00 <?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\WebLink; use Psr\Link\EvolvableLinkProviderInterface; use Psr\Link\LinkInterface; class GenericLinkProvider implements EvolvableLinkProviderInterface { /** * @var LinkInterface[] */ private $links = []; /** * @param LinkInterface[] $links */ public function __construct(array $links = []) { $that = $this; foreach ($links as $link) { $that = $that->withLink($link); } $this->links = $that->links; } /** * {@inheritdoc} */ public function getLinks(): array { return array_values($this->links); } /** * {@inheritdoc} */ public function getLinksByRel($rel): array { $links = []; foreach ($this->links as $link) { if (\in_array($rel, $link->getRels())) { $links[] = $link; } } return $links; } /** * {@inheritdoc} * * @return static */ public function withLink(LinkInterface $link) { $that = clone $this; $that->links[spl_object_id($link)] = $link; return $that; } /** * {@inheritdoc} * * @return static */ public function withoutLink(LinkInterface $link) { $that = clone $this; unset($that->links[spl_object_id($link)]); return $that; } } LICENSE 0000644 00000002054 15173176015 0005560 0 ustar 00 Copyright (c) 2004-present Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. HttpHeaderSerializer.php 0000644 00000003331 15173176015 0011345 0 ustar 00 <?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\WebLink; use Psr\Link\LinkInterface; /** * Serializes a list of Link instances to an HTTP Link header. * * @see https://tools.ietf.org/html/rfc5988 * * @author Kévin Dunglas <dunglas@gmail.com> */ final class HttpHeaderSerializer { /** * Builds the value of the "Link" HTTP header. * * @param LinkInterface[]|\Traversable $links */ public function serialize(iterable $links): ?string { $elements = []; foreach ($links as $link) { if ($link->isTemplated()) { continue; } $attributesParts = ['', sprintf('rel="%s"', implode(' ', $link->getRels()))]; foreach ($link->getAttributes() as $key => $value) { if (\is_array($value)) { foreach ($value as $v) { $attributesParts[] = sprintf('%s="%s"', $key, preg_replace('/(?<!\\\\)"/', '\"', $v)); } continue; } if (!\is_bool($value)) { $attributesParts[] = sprintf('%s="%s"', $key, preg_replace('/(?<!\\\\)"/', '\"', $value)); continue; } if (true === $value) { $attributesParts[] = $key; } } $elements[] = sprintf('<%s>%s', $link->getHref(), implode('; ', $attributesParts)); } return $elements ? implode(',', $elements) : null; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings