vendor/symfony/web-link/Link.php line 16

  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\WebLink;
  11. use Psr\Link\EvolvableLinkInterface;
  12. class Link implements EvolvableLinkInterface
  13. {
  14.     // @see https://www.iana.org/assignments/link-relations/link-relations.xhtml
  15.     public const REL_ABOUT 'about';
  16.     public const REL_ACL 'acl';
  17.     public const REL_ALTERNATE 'alternate';
  18.     public const REL_AMPHTML 'amphtml';
  19.     public const REL_APPENDIX 'appendix';
  20.     public const REL_APPLE_TOUCH_ICON 'apple-touch-icon';
  21.     public const REL_APPLE_TOUCH_STARTUP_IMAGE 'apple-touch-startup-image';
  22.     public const REL_ARCHIVES 'archives';
  23.     public const REL_AUTHOR 'author';
  24.     public const REL_BLOCKED_BY 'blocked-by';
  25.     public const REL_BOOKMARK 'bookmark';
  26.     public const REL_CANONICAL 'canonical';
  27.     public const REL_CHAPTER 'chapter';
  28.     public const REL_CITE_AS 'cite-as';
  29.     public const REL_COLLECTION 'collection';
  30.     public const REL_CONTENTS 'contents';
  31.     public const REL_CONVERTEDFROM 'convertedfrom';
  32.     public const REL_COPYRIGHT 'copyright';
  33.     public const REL_CREATE_FORM 'create-form';
  34.     public const REL_CURRENT 'current';
  35.     public const REL_DESCRIBEDBY 'describedby';
  36.     public const REL_DESCRIBES 'describes';
  37.     public const REL_DISCLOSURE 'disclosure';
  38.     public const REL_DNS_PREFETCH 'dns-prefetch';
  39.     public const REL_DUPLICATE 'duplicate';
  40.     public const REL_EDIT 'edit';
  41.     public const REL_EDIT_FORM 'edit-form';
  42.     public const REL_EDIT_MEDIA 'edit-media';
  43.     public const REL_ENCLOSURE 'enclosure';
  44.     public const REL_EXTERNAL 'external';
  45.     public const REL_FIRST 'first';
  46.     public const REL_GLOSSARY 'glossary';
  47.     public const REL_HELP 'help';
  48.     public const REL_HOSTS 'hosts';
  49.     public const REL_HUB 'hub';
  50.     public const REL_ICON 'icon';
  51.     public const REL_INDEX 'index';
  52.     public const REL_INTERVALAFTER 'intervalafter';
  53.     public const REL_INTERVALBEFORE 'intervalbefore';
  54.     public const REL_INTERVALCONTAINS 'intervalcontains';
  55.     public const REL_INTERVALDISJOINT 'intervaldisjoint';
  56.     public const REL_INTERVALDURING 'intervalduring';
  57.     public const REL_INTERVALEQUALS 'intervalequals';
  58.     public const REL_INTERVALFINISHEDBY 'intervalfinishedby';
  59.     public const REL_INTERVALFINISHES 'intervalfinishes';
  60.     public const REL_INTERVALIN 'intervalin';
  61.     public const REL_INTERVALMEETS 'intervalmeets';
  62.     public const REL_INTERVALMETBY 'intervalmetby';
  63.     public const REL_INTERVALOVERLAPPEDBY 'intervaloverlappedby';
  64.     public const REL_INTERVALOVERLAPS 'intervaloverlaps';
  65.     public const REL_INTERVALSTARTEDBY 'intervalstartedby';
  66.     public const REL_INTERVALSTARTS 'intervalstarts';
  67.     public const REL_ITEM 'item';
  68.     public const REL_LAST 'last';
  69.     public const REL_LATEST_VERSION 'latest-version';
  70.     public const REL_LICENSE 'license';
  71.     public const REL_LINKSET 'linkset';
  72.     public const REL_LRDD 'lrdd';
  73.     public const REL_MANIFEST 'manifest';
  74.     public const REL_MASK_ICON 'mask-icon';
  75.     public const REL_MEDIA_FEED 'media-feed';
  76.     public const REL_MEMENTO 'memento';
  77.     public const REL_MICROPUB 'micropub';
  78.     public const REL_MODULEPRELOAD 'modulepreload';
  79.     public const REL_MONITOR 'monitor';
  80.     public const REL_MONITOR_GROUP 'monitor-group';
  81.     public const REL_NEXT 'next';
  82.     public const REL_NEXT_ARCHIVE 'next-archive';
  83.     public const REL_NOFOLLOW 'nofollow';
  84.     public const REL_NOOPENER 'noopener';
  85.     public const REL_NOREFERRER 'noreferrer';
  86.     public const REL_OPENER 'opener';
  87.     public const REL_OPENID_2_LOCAL_ID 'openid2.local_id';
  88.     public const REL_OPENID_2_PROVIDER 'openid2.provider';
  89.     public const REL_ORIGINAL 'original';
  90.     public const REL_P_3_PV_1 'p3pv1';
  91.     public const REL_PAYMENT 'payment';
  92.     public const REL_PINGBACK 'pingback';
  93.     public const REL_PRECONNECT 'preconnect';
  94.     public const REL_PREDECESSOR_VERSION 'predecessor-version';
  95.     public const REL_PREFETCH 'prefetch';
  96.     public const REL_PRELOAD 'preload';
  97.     public const REL_PRERENDER 'prerender';
  98.     public const REL_PREV 'prev';
  99.     public const REL_PREVIEW 'preview';
  100.     public const REL_PREVIOUS 'previous';
  101.     public const REL_PREV_ARCHIVE 'prev-archive';
  102.     public const REL_PRIVACY_POLICY 'privacy-policy';
  103.     public const REL_PROFILE 'profile';
  104.     public const REL_PUBLICATION 'publication';
  105.     public const REL_RELATED 'related';
  106.     public const REL_RESTCONF 'restconf';
  107.     public const REL_REPLIES 'replies';
  108.     public const REL_RULEINPUT 'ruleinput';
  109.     public const REL_SEARCH 'search';
  110.     public const REL_SECTION 'section';
  111.     public const REL_SELF 'self';
  112.     public const REL_SERVICE 'service';
  113.     public const REL_SERVICE_DESC 'service-desc';
  114.     public const REL_SERVICE_DOC 'service-doc';
  115.     public const REL_SERVICE_META 'service-meta';
  116.     public const REL_SIPTRUNKINGCAPABILITY 'siptrunkingcapability';
  117.     public const REL_SPONSORED 'sponsored';
  118.     public const REL_START 'start';
  119.     public const REL_STATUS 'status';
  120.     public const REL_STYLESHEET 'stylesheet';
  121.     public const REL_SUBSECTION 'subsection';
  122.     public const REL_SUCCESSOR_VERSION 'successor-version';
  123.     public const REL_SUNSET 'sunset';
  124.     public const REL_TAG 'tag';
  125.     public const REL_TERMS_OF_SERVICE 'terms-of-service';
  126.     public const REL_TIMEGATE 'timegate';
  127.     public const REL_TIMEMAP 'timemap';
  128.     public const REL_TYPE 'type';
  129.     public const REL_UGC 'ugc';
  130.     public const REL_UP 'up';
  131.     public const REL_VERSION_HISTORY 'version-history';
  132.     public const REL_VIA 'via';
  133.     public const REL_WEBMENTION 'webmention';
  134.     public const REL_WORKING_COPY 'working-copy';
  135.     public const REL_WORKING_COPY_OF 'working-copy-of';
  136.     // Extra relations
  137.     public const REL_MERCURE 'mercure';
  138.     private string $href '';
  139.     /**
  140.      * @var string[]
  141.      */
  142.     private array $rel = [];
  143.     /**
  144.      * @var array<string, string|bool|string[]>
  145.      */
  146.     private array $attributes = [];
  147.     public function __construct(?string $rel nullstring $href '')
  148.     {
  149.         if (null !== $rel) {
  150.             $this->rel[$rel] = $rel;
  151.         }
  152.         $this->href $href;
  153.     }
  154.     public function getHref(): string
  155.     {
  156.         return $this->href;
  157.     }
  158.     public function isTemplated(): bool
  159.     {
  160.         return $this->hrefIsTemplated($this->href);
  161.     }
  162.     public function getRels(): array
  163.     {
  164.         return array_values($this->rel);
  165.     }
  166.     public function getAttributes(): array
  167.     {
  168.         return $this->attributes;
  169.     }
  170.     public function withHref(string|\Stringable $href): static
  171.     {
  172.         $that = clone $this;
  173.         $that->href $href;
  174.         return $that;
  175.     }
  176.     public function withRel(string $rel): static
  177.     {
  178.         $that = clone $this;
  179.         $that->rel[$rel] = $rel;
  180.         return $that;
  181.     }
  182.     public function withoutRel(string $rel): static
  183.     {
  184.         $that = clone $this;
  185.         unset($that->rel[$rel]);
  186.         return $that;
  187.     }
  188.     public function withAttribute(string $attributestring|\Stringable|int|float|bool|array $value): static
  189.     {
  190.         $that = clone $this;
  191.         $that->attributes[$attribute] = $value;
  192.         return $that;
  193.     }
  194.     public function withoutAttribute(string $attribute): static
  195.     {
  196.         $that = clone $this;
  197.         unset($that->attributes[$attribute]);
  198.         return $that;
  199.     }
  200.     private function hrefIsTemplated(string $href): bool
  201.     {
  202.         return str_contains($href'{') || str_contains($href'}');
  203.     }
  204. }