Skip to content

Commit a277eab

Browse files
committed
Improve autoconversion for containers
1 parent e44e7c1 commit a277eab

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

docs/basic-usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ $permissions['geolocation'][-1]->value(); // returns the last value of the
3535
$permissions['camera']->value(); // returns '*' the sole value attached to the 'camera' feature
3636
isset($permissions['yolo']); // returns false this permission does not exust
3737
$permissions->isEmpty(); // returns false the dictionary contains some permissions
38+
echo $permissions; // returns 'picture-in-picture=(), geolocation=(self "https://example.com/"), camera=*'
3839
```
3940

4041
> [!WARNING]

docs/containers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ echo $field->removeByKeys('expire', 'httponly', 'max-age')->toHttpValue(); // re
236236

237237
### Automatic conversion
238238

239-
Learning new types may be a daunting tasks so for ease of usage, for all containers, the following automatic
240-
conversion are applied on the member argument of each modifying methods.
239+
Learning new types may be a daunting tasks so for ease of usage, all datatype can be represented using an array as list.
240+
The automatic conversion are applied on the member argument of each modifying methods>
241241

242242
If the submitted type is:
243243

src/InnerList.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
* @see https://www.rfc-editor.org/rfc/rfc9651.html#section-3.1.1
3030
*
3131
* @phpstan-import-type SfType from StructuredFieldProvider
32+
* @phpstan-import-type SfTypeInput from StructuredFieldProvider
3233
* @phpstan-import-type SfItemInput from StructuredFieldProvider
34+
* @phpstan-import-type SfItemPair from StructuredFieldProvider
3335
* @phpstan-import-type SfInnerListPair from StructuredFieldProvider
3436
* @phpstan-import-type SfParameterInput from StructuredFieldProvider
3537
*
@@ -45,7 +47,7 @@ final class InnerList implements ArrayAccess, Countable, IteratorAggregate
4547
private readonly Parameters $parameters;
4648

4749
/**
48-
* @param iterable<SfItemInput> $members
50+
* @param iterable<SfItemInput|SfItemPair> $members
4951
*/
5052
private function __construct(iterable $members, ?Parameters $parameters = null)
5153
{
@@ -54,7 +56,7 @@ private function __construct(iterable $members, ?Parameters $parameters = null)
5456
}
5557

5658
/**
57-
* @param SfItemInput $member
59+
* @param SfItemInput|SfItemPair $member
5860
*/
5961
private function filterMember(mixed $member): Item
6062
{
@@ -141,9 +143,11 @@ public static function fromPair(array $pair): self
141143

142144
/**
143145
* Returns a new instance.
146+
*
147+
* @param StructuredFieldProvider|Item|SfTypeInput|SfItemPair ...$members
144148
*/
145149
public static function new(
146-
StructuredFieldProvider|OuterList|Dictionary|InnerList|Parameters|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members
150+
StructuredFieldProvider|Item|Token|Bytes|DisplayString|DateTimeInterface|array|string|int|float|bool ...$members
147151
): self {
148152
return new self($members);
149153
}

src/Item.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public static function tryFromPair(array $pair): ?self
114114
*/
115115
public static function fromPair(array $pair): self
116116
{
117+
;
117118
if ([] === $pair || !array_is_list($pair) || 2 < count($pair)) {
118119
throw new SyntaxError('The pair must be represented by an non-empty array as a list containing exactly 1 or 2 members.');
119120
}
@@ -141,7 +142,7 @@ public static function fromPair(array $pair): self
141142
/**
142143
* Returns a new bare instance from value.
143144
*
144-
* @param SfItemInput|array{0:SfItemInput, 1:Parameters|iterable<array{0:string, 1:SfItemInput}>} $value
145+
* @param SfItemInput|SfItemPair $value
145146
*
146147
* @throws SyntaxError If the value is not valid.
147148
*/

src/OuterList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ public static function fromPairs(StructuredFieldProvider|iterable $pairs): self
141141
}
142142

143143
/**
144-
* @param SfMemberInput ...$members
144+
* @param StructuredFieldProvider|SfInnerListPair|SfItemPair|SfMemberInput ...$members
145145
*/
146146
public static function new(iterable|StructuredFieldProvider|InnerList|Item|Token|Bytes|DisplayString|DateTimeInterface|string|int|float|bool ...$members): self
147147
{
148-
return new self(...$members);
148+
return self::fromPairs($members); /* @phpstan-ignore-line*/
149149
}
150150

151151
public static function fromRfc9651(Stringable|string $httpValue): self

0 commit comments

Comments
 (0)