[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <[email protected]> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\WebLink; 13 14 use Psr\Link\EvolvableLinkInterface; 15 16 class Link implements EvolvableLinkInterface 17 { 18 // Relations defined in https://www.w3.org/TR/html5/links.html#links and applicable on link elements 19 public const REL_ALTERNATE = 'alternate'; 20 public const REL_AUTHOR = 'author'; 21 public const REL_HELP = 'help'; 22 public const REL_ICON = 'icon'; 23 public const REL_LICENSE = 'license'; 24 public const REL_SEARCH = 'search'; 25 public const REL_STYLESHEET = 'stylesheet'; 26 public const REL_NEXT = 'next'; 27 public const REL_PREV = 'prev'; 28 29 // Relation defined in https://www.w3.org/TR/preload/ 30 public const REL_PRELOAD = 'preload'; 31 32 // Relations defined in https://www.w3.org/TR/resource-hints/ 33 public const REL_DNS_PREFETCH = 'dns-prefetch'; 34 public const REL_PRECONNECT = 'preconnect'; 35 public const REL_PREFETCH = 'prefetch'; 36 public const REL_PRERENDER = 'prerender'; 37 38 // Extra relations 39 public const REL_MERCURE = 'mercure'; 40 41 private $href = ''; 42 43 /** 44 * @var string[] 45 */ 46 private $rel = []; 47 48 /** 49 * @var array<string, string|bool|string[]> 50 */ 51 private $attributes = []; 52 53 public function __construct(string $rel = null, string $href = '') 54 { 55 if (null !== $rel) { 56 $this->rel[$rel] = $rel; 57 } 58 $this->href = $href; 59 } 60 61 /** 62 * {@inheritdoc} 63 */ 64 public function getHref(): string 65 { 66 return $this->href; 67 } 68 69 /** 70 * {@inheritdoc} 71 */ 72 public function isTemplated(): bool 73 { 74 return $this->hrefIsTemplated($this->href); 75 } 76 77 /** 78 * {@inheritdoc} 79 */ 80 public function getRels(): array 81 { 82 return array_values($this->rel); 83 } 84 85 /** 86 * {@inheritdoc} 87 */ 88 public function getAttributes(): array 89 { 90 return $this->attributes; 91 } 92 93 /** 94 * {@inheritdoc} 95 * 96 * @return static 97 */ 98 public function withHref($href) 99 { 100 $that = clone $this; 101 $that->href = $href; 102 103 return $that; 104 } 105 106 /** 107 * {@inheritdoc} 108 * 109 * @return static 110 */ 111 public function withRel($rel) 112 { 113 $that = clone $this; 114 $that->rel[$rel] = $rel; 115 116 return $that; 117 } 118 119 /** 120 * {@inheritdoc} 121 * 122 * @return static 123 */ 124 public function withoutRel($rel) 125 { 126 $that = clone $this; 127 unset($that->rel[$rel]); 128 129 return $that; 130 } 131 132 /** 133 * {@inheritdoc} 134 * 135 * @param string|\Stringable|int|float|bool|string[] $value 136 * 137 * @return static 138 */ 139 public function withAttribute($attribute, $value) 140 { 141 $that = clone $this; 142 $that->attributes[$attribute] = $value; 143 144 return $that; 145 } 146 147 /** 148 * {@inheritdoc} 149 * 150 * @return static 151 */ 152 public function withoutAttribute($attribute) 153 { 154 $that = clone $this; 155 unset($that->attributes[$attribute]); 156 157 return $that; 158 } 159 160 private function hrefIsTemplated(string $href): bool 161 { 162 return str_contains($href, '{') || str_contains($href, '}'); 163 } 164 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |