@@ -6313,12 +6313,9 @@ public function encode(Document $collection, Document $document): Document
63136313 {
63146314 $ attributes = $ collection ->getAttribute ('attributes ' , []);
63156315
6316- $ internalAttributes = \array_filter (Database::INTERNAL_ATTRIBUTES , function ($ attribute ) {
6317- // We don't want to encode permissions into a JSON string
6318- return $ attribute ['$id ' ] !== '$permissions ' ;
6319- });
6320-
6321- $ attributes = \array_merge ($ attributes , $ internalAttributes );
6316+ foreach ($ this ->getInternalAttributes () as $ attribute ) {
6317+ $ attributes [] = $ attribute ;
6318+ }
63226319
63236320 foreach ($ attributes as $ attribute ) {
63246321 $ key = $ attribute ['$id ' ] ?? '' ;
@@ -6327,6 +6324,13 @@ public function encode(Document $collection, Document $document): Document
63276324 $ filters = $ attribute ['filters ' ] ?? [];
63286325 $ value = $ document ->getAttribute ($ key );
63296326
6327+ if ($ key === '$permissions ' ) {
6328+ if (empty ($ value )) {
6329+ $ document ->setAttribute ('$permissions ' , []); // set default value
6330+ }
6331+ continue ;
6332+ }
6333+
63306334 // Continue on optional param with no default
63316335 if (is_null ($ value ) && is_null ($ default )) {
63326336 continue ;
@@ -6394,7 +6398,9 @@ public function decode(Document $collection, Document $document, array $selectio
63946398 }
63956399 }
63966400
6397- $ attributes = \array_merge ($ attributes , $ this ->getInternalAttributes ());
6401+ foreach ($ this ->getInternalAttributes () as $ attribute ) {
6402+ $ attributes [] = $ attribute ;
6403+ }
63986404
63996405 foreach ($ attributes as $ attribute ) {
64006406 $ key = $ attribute ['$id ' ] ?? '' ;
@@ -6413,10 +6419,11 @@ public function decode(Document $collection, Document $document, array $selectio
64136419 $ value = ($ array ) ? $ value : [$ value ];
64146420 $ value = (is_null ($ value )) ? [] : $ value ;
64156421
6416- foreach ($ value as & $ node ) {
6417- foreach (\ array_reverse ($ filters ) as $ filter ) {
6422+ foreach ($ value as $ index => $ node ) {
6423+ foreach (array_reverse ($ filters ) as $ filter ) {
64186424 $ node = $ this ->decodeAttribute ($ filter , $ node , $ document , $ key );
64196425 }
6426+ $ value [$ index ] = $ node ;
64206427 }
64216428
64226429 if (
@@ -6447,7 +6454,9 @@ public function casting(Document $collection, Document $document): Document
64476454
64486455 $ attributes = $ collection ->getAttribute ('attributes ' , []);
64496456
6450- $ attributes = \array_merge ($ attributes , $ this ->getInternalAttributes ());
6457+ foreach ($ this ->getInternalAttributes () as $ attribute ) {
6458+ $ attributes [] = $ attribute ;
6459+ }
64516460
64526461 foreach ($ attributes as $ attribute ) {
64536462 $ key = $ attribute ['$id ' ] ?? '' ;
@@ -6466,7 +6475,7 @@ public function casting(Document $collection, Document $document): Document
64666475 $ value = [$ value ];
64676476 }
64686477
6469- foreach ($ value as & $ node ) {
6478+ foreach ($ value as $ index => $ node ) {
64706479 switch ($ type ) {
64716480 case self ::VAR_BOOLEAN :
64726481 $ node = (bool )$ node ;
@@ -6480,6 +6489,8 @@ public function casting(Document $collection, Document $document): Document
64806489 default :
64816490 break ;
64826491 }
6492+
6493+ $ value [$ index ] = $ node ;
64836494 }
64846495
64856496 $ document ->setAttribute ($ key , ($ array ) ? $ value : $ value [0 ]);
0 commit comments