8000 Add specific attribute types and update parser return type · symfony/symfony@66d0222 · GitHub
[go: up one dir, main page]

Skip to content

Commit 66d0222

Browse files
committed
Add specific attribute types and update parser return type
1 parent 3f9c12e commit 66d0222

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/Symfony/Component/WebLink/HttpHeaderParser.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\WebLink;
1313

14+
use Psr\Link\EvolvableLinkProviderInterface;
15+
1416
/**
1517
* Parse a list of HTTP Link headers into a list of Link instances.
1618
*
@@ -29,12 +31,14 @@ class HttpHeaderParser
2931
/**
3032
* @param string|string[] $headers Value of the "Link" HTTP header
3133
*/
32-
public function parse(string|array $headers): GenericLinkProvider
34+
public function parse(string|array $headers): EvolvableLinkProviderInterface
3335
{
34-
$headerString = is_array($headers) ? implode(',', $headers) : $headers;
36+
if (is_array($headers)) {
37+
$headers = implode(', ', $headers);
38+
}
3539
$links = new GenericLinkProvider();
3640

37-
if (!preg_match_all(self::LINK_PATTERN, $headerString, $matches, PREG_SET_ORDER)) {
41+
if (!preg_match_all(self::LINK_PATTERN, $headers, $matches, \PREG_SET_ORDER)) {
3842
return $links;
3943
}
4044

@@ -43,7 +47,7 @@ public function parse(string|array $headers): GenericLinkProvider
4347
$paramsString = $match[2];
4448

4549
$params = [];
46-
if (preg_match_all(self::PARAM_PATTERN, $paramsString, $paramMatches, PREG_SET_ORDER)) {
50+
if (preg_match_all(self::PARAM_PATTERN, $paramsString, $paramMatches, \PREG_SET_ORDER)) {
4751
foreach ($paramMatches as $pm) {
4852
$key = $pm[1];
4953
$value = match (true) {

src/Symfony/Component/WebLink/Link.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,21 @@ public function getRels(): array
175175
return array_values($this->rel);
176176
}
177177

178+
/**
179+
* Returns a list of attributes that describe the target URI.
180+
*
181+
* @return array<string, string|\Stringable|int|float|bool|list<string|\Stringable|int|float|bool>>
182+
*/
178183
public function getAttributes(): array
179184
{
180185
return $this->attributes;
181186
}
182187

188+
/**
189+
* Return values of the given attribute that describes the target URI.
190+
*
191+
* @return string|\Stringable|int|float|bool|list<string|\Stringable|int|float|bool>|null
192+
*/
183193
public function getAttribute(string $attribute): string|\Stringable|int|float|bool|array|null
184194
{
185195
return $this->attributes[$attribute] ?? null;
@@ -209,6 +219,14 @@ public function withoutRel(string $rel): static
209219
return $that;
210220
}
211221

222+
/**
223+
* Returns an instance with the specified attribute added.
224+
*
225+
* If the specified attribute is already present, it will be overwritten
226+
* with the new value.
227+
*
228+
* @param string|\Stringable|int|float|bool|list<string|\Stringable|int|float|bool> $value
229+
*/
212230
public function withAttribute(string $attribute, string|\Stringable|int|float|bool|array $value): static
213231
{
214232
$that = clone $this;

0 commit comments

Comments
 (0)
0