12
12
use Iterator ;
13
13
use IteratorAggregate ;
14
14
use Stringable ;
15
+ use Throwable ;
15
16
16
17
use function array_key_exists ;
17
18
use function array_keys ;
@@ -80,7 +81,7 @@ public static function new(): self
80
81
/**
81
82
* Returns a new instance from an associative iterable construct.
82
83
*
83
- * its keys represent the dictionary entry key
84
+ * its keys represent the dictionary entry name
84
85
* its values represent the dictionary entry value
85
86
*
86
87
* @param StructuredFieldProvider|iterable<string, InnerList|Item|SfMemberInput> $members
@@ -102,12 +103,12 @@ public static function fromAssociative(StructuredFieldProvider|iterable $members
102
103
* Returns a new instance from a pair iterable construct.
103
104
*
104
105
* Each member is composed of an array with two elements
105
- * the first member represents the instance entry key
106
+ * the first member represents the instance entry name
106
107
* the second member represents the instance entry value
107
108
*
108
109
* @param StructuredFieldProvider|Dictionary|Parameters|iterable<array{0:string, 1?:InnerList|Item|SfMemberInput}> $pairs
109
110
*/
110
- public static function fromPairs (StructuredFieldProvider |iterable $ pairs ): self
111
+ public static function fromPairs (StructuredFieldProvider |Dictionary | Parameters | iterable $ pairs ): self
111
112
{
112
113
if ($ pairs instanceof StructuredFieldProvider) {
113
114
$ pairs = $ pairs ->toStructuredField ();
@@ -163,7 +164,7 @@ public static function fromPairs(StructuredFieldProvider|iterable $pairs): self
163
164
*
164
165
* @see https://www.rfc-editor.org/rfc/rfc9651.html#section-3.2
165
166
*
166
- * @throws SyntaxError If the string is not a valid
167
+ * @throws StructuredFieldError|Throwable
167
168
*/
168
169
public static function fromRfc9651 (Stringable |string $ httpValue ): self
169
170
{
@@ -175,7 +176,7 @@ public static function fromRfc9651(Stringable|string $httpValue): self
175
176
*
176
177
* @see https://www.rfc-editor.org/rfc/rfc8941.html#section-3.2
177
178
*
178
- * @throws SyntaxError If the string is not a valid
179
+ * @throws StructuredFieldError|Throwable
179
180
*/
180
181
public static function fromRfc8941 (Stringable |string $ httpValue ): self
181
182
{
@@ -187,7 +188,7 @@ public static function fromRfc8941(Stringable|string $httpValue): self
187
188
*
188
189
* @see https://www.rfc-editor.org/rfc/rfc9651.html#section-3.2
189
190
*
190
- * @throws SyntaxError If the string is not a valid
191
+ * @throws StructuredFieldError|Throwable If the string is not a valid
191
192
*/
192
193
public static function fromHttpValue (Stringable |string $ httpValue , ?Ietf $ rfc = null ): self
193
194
{
@@ -380,7 +381,7 @@ private function filterIndex(int $index, int|null $max = null): int|null
380
381
}
381
382
382
383
/**
383
- * Returns the item or the inner-list and its key as attached to the given
384
+ * Returns the item or the inner-list and its name as attached to the given
384
385
* collection according to their index position otherwise throw.
385
386
*
386
387
* @param ?callable(Item|InnerList, string): (bool|string) $validate
@@ -418,7 +419,7 @@ public function getByIndex(int $index, ?callable $validate = null): array
418
419
}
419
420
420
421
/**
421
- * Returns the key associated with the given index or null otherwise.
422
+ * Returns the name associated with the given index or null otherwise.
422
423
*/
423
424
public function indexByName (string $ name ): ?int
424
425
{
@@ -451,7 +452,7 @@ public function nameByIndex(int $index): ?string
451
452
}
452
453
453
454
/**
454
- * Returns the first member whether it is an item or an inner-list and its key as attached to the given
455
+ * Returns the first member whether it is an item or an inner-list and its name as attached to the given
455
456
* collection according to their index position otherwise returns an empty array.
456
457
*
457
458
* @return array{0:string, 1:InnerList|Item}|array{}
@@ -460,13 +461,13 @@ public function first(): array
460
461
{
461
462
try {
462
463
return $ this ->getByIndex (0 );
463
- } catch (InvalidOffset ) {
464
+ } catch (StructuredFieldError ) {
464
465
return [];
465
466
}
466
467
}
467
468
468
469
/**
469
- * Returns the first member whether it is an item or an inner-list and its key as attached to the given
470
+ * Returns the first member whether it is an item or an inner-list and its name as attached to the given
470
471
* collection according to their index position otherwise returns an empty array.
471
472
*
472
473
* @return array{0:string, 1:InnerList|Item}|array{}
@@ -475,24 +476,24 @@ public function last(): array
475
476
{
476
477
try {
477
478
return $ this ->getByIndex (-1 );
478
- } catch (InvalidOffset ) {
479
+ } catch (StructuredFieldError ) {
479
480
return [];
480
481
}
481
482
}
482
483
483
484
/**
484
- * Adds a member at the end of the instance otherwise updates the value associated with the key if already present.
485
+ * Adds a member at the end of the instance otherwise updates the value associated with the name if already present.
485
486
*
486
487
* This method MUST retain the state of the current instance, and return
487
488
* an instance that contains the specified changes.
488
489
*
489
490
* @param InnerList|Item|SfMemberInput|null $member
490
491
*
491
- * @throws SyntaxError If the string key is not a valid
492
+ * @throws SyntaxError If the string name is not a valid
492
493
*/
493
494
public function add (
494
495
string $ name ,
495
- iterable |StructuredFieldProvider |OuterList |Dictionary |InnerList |Parameters |Item |Token |ByteSequence |DisplayString |DateTimeInterface |string |int |float |bool |null $ member
496
+ iterable |StructuredFieldProvider |OuterList |Dictionary |InnerList |Parameters |Item |Token |Byte |DisplayString |DateTimeInterface |string |int |float |bool |null $ member
496
497
): self {
497
498
if (null === $ member ) {
498
499
return $ this ;
@@ -561,7 +562,7 @@ public function removeByIndices(int ...$indices): self
561
562
}
562
563
563
564
/**
564
- * Deletes members associated with the list using the member key .
565
+ * Deletes members associated with the list using the member name .
565
566
*
566
567
* This method MUST retain the state of the current instance, and return
567
568
* an instance that contains the specified changes.
@@ -572,17 +573,17 @@ public function removeByNames(string ...$names): self
572
573
}
573
574
574
575
/**
575
- * Adds a member at the end of the instance and deletes any previous reference to the key if present.
576
+ * Adds a member at the end of the instance and deletes any previous reference to the name if present.
576
577
*
577
578
* This method MUST retain the state of the current instance, and return
578
579
* an instance that contains the specified changes.
579
580
*
580
581
* @param InnerList|Item|SfMemberInput|null $member
581
- * @throws SyntaxError If the string key is not a valid
582
+ * @throws SyntaxError If the string name is not a valid
582
583
*/
583
584
public function append (
584
585
string $ name ,
585
- iterable |StructuredFieldProvider |OuterList |Dictionary |InnerList |Parameters |Item |Token |ByteSequence |DisplayString |DateTimeInterface |string |int |float |bool |null $ member
586
+ iterable |StructuredFieldProvider |OuterList |Dictionary |InnerList |Parameters |Item |Token |Byte |DisplayString |DateTimeInterface |string |int |float |bool |null $ member
586
587
): self {
587
588
if (null === $ member ) {
588
589
return $ this ;
@@ -594,18 +595,18 @@ public function append(
594
595
}
595
596
596
597
/**
597
- * Adds a member at the beginning of the instance and deletes any previous reference to the key if present.
598
+ * Adds a member at the beginning of the instance and deletes any previous reference to the name if present.
598
599
*
599
600
* This method MUST retain the state of the current instance, and return
600
601
* an instance that contains the specified changes.
601
602
*
602
603
* @param InnerList|Item|SfMemberInput|null $member
603
604
*
604
- * @throws SyntaxError If the string key is not a valid
605
+ * @throws SyntaxError If the string name is not a valid
605
606
*/
606
607
public function prepend (
607
608
string $ name ,
608
- iterable |StructuredFieldProvider |OuterList |Dictionary |InnerList |Parameters |Item |Token |ByteSequence |DisplayString |DateTimeInterface |string |int |float |bool |null $ member
609
+ iterable |StructuredFieldProvider |OuterList |Dictionary |InnerList |Parameters |Item |Token |Byte |DisplayString |DateTimeInterface |string |int |float |bool |null $ member
609
610
): self {
610
611
if (null === $ member ) {
611
612
return $ this ;
@@ -763,6 +764,8 @@ public function offsetExists(mixed $offset): bool
763
764
764
765
/**
765
766
* @param string $offset
767
+ *
768
+ * @throws StructuredFieldError
766
769
*/
767
770
public function offsetGet (mixed $ offset ): InnerList |Item
768
771
{
@@ -790,7 +793,7 @@ public function offsetSet(mixed $offset, mixed $value): void
790
793
*/
791
794
public function map (callable $ callback ): Iterator
792
795
{
793
- foreach ($ this -> getIterator () as $ offset => $ member ) {
796
+ foreach ($ this as $ offset => $ member ) {
794
797
yield ($ callback )($ member , $ offset );
795
798
}
796
799
}
@@ -805,7 +808,7 @@ public function map(callable $callback): Iterator
805
808
*/
806
809
public function reduce (callable $ callback , mixed $ initial = null ): mixed
807
810
{
808
- foreach ($ this -> getIterator () as $ offset => $ pair ) {
811
+ foreach ($ this as $ offset => $ pair ) {
809
812
$ initial = $ callback ($ initial , $ pair , $ offset );
810
813
}
811
814
@@ -819,7 +822,7 @@ public function reduce(callable $callback, mixed $initial = null): mixed
819
822
*/
820
823
public function filter (callable $ callback ): self
821
824
{
822
- return self ::fromPairs (new CallbackFilterIterator ($ this -> getIterator () , $ callback ));
825
+ return self ::fromPairs (new CallbackFilterIterator ($ this , $ callback ));
823
826
}
824
827
825
828
/**
@@ -829,7 +832,7 @@ public function filter(callable $callback): self
829
832
*/
830
833
public function sort (callable $ callback ): self
831
834
{
832
- $ members = iterator_to_array ($ this -> getIterator () );
835
+ $ members = iterator_to_array ($ this );
833
836
usort ($ members , $ callback );
834
837
835
838
return self ::fromPairs ($ members );
0 commit comments