File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed
Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 1414
1515class Attributes implements Arrayable
1616{
17- private const RELATION_MARKER = 'relations: ' ;
17+ private const string RELATION_MARKER = 'relations: ' ;
18+ private const string DYNAMIC_COUNT_MARKER = '* ' ;
1819 private array $ params ;
1920 private array $ attributes = [];
2021 /** @var array<self> */
@@ -97,7 +98,7 @@ private function parseParameters(array $params): void
9798 $ attributes = [];
9899 $ relations = [];
99100 foreach ($ params as $ key => $ data ) {
100- if (str_starts_with ($ key , self ::RELATION_MARKER )) {
101+ if (str_starts_with (( string ) $ key , self ::RELATION_MARKER )) {
101102 $ ex = explode (': ' , $ key );
102103 if (! isset ($ ex [1 ])) {
103104 throw new InvalidArgumentException ('Relation is empty ' );
@@ -106,9 +107,9 @@ private function parseParameters(array $params): void
106107 $ relName = $ ex [1 ];
107108 $ count = 1 ;
108109 if (isset ($ ex [2 ])) {
109- $ count = (int ) $ ex [2 ];
110+ $ count = $ ex [ 2 ] === self :: DYNAMIC_COUNT_MARKER ? count ( $ data ) : (int ) $ ex [2 ];
110111 }
111- $ attrs = $ params [ $ key ] ;
112+ $ attrs = $ data ;
112113
113114 $ relations [$ relName ] = new self ($ attrs , $ relName , $ count );
114115 } else {
You can’t perform that action at this time.
0 commit comments