-
Notifications
You must be signed in to change notification settings - Fork 55
Fix encoding decoding #639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
f28deb4
398e71b
9c24931
dd90655
a41d4ad
360a6e9
10e7a0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6292,12 +6292,11 @@ public function encode(Document $collection, Document $document): Document | |
| { | ||
| $attributes = $collection->getAttribute('attributes', []); | ||
|
|
||
| $internalAttributes = \array_filter(Database::INTERNAL_ATTRIBUTES, function ($attribute) { | ||
| // We don't want to encode permissions into a JSON string | ||
| return $attribute['$id'] !== '$permissions'; | ||
| }); | ||
|
|
||
| $attributes = \array_merge($attributes, $internalAttributes); | ||
| foreach ($this->getInternalAttributes() as $attribute) { | ||
| if ($attribute['$id'] !== '$permissions') { // Don't encode permissions into a JSON string | ||
| $attributes[] = new Document($attribute); | ||
| } | ||
| } | ||
|
|
||
| foreach ($attributes as $attribute) { | ||
| $key = $attribute['$id'] ?? ''; | ||
|
|
@@ -6362,18 +6361,19 @@ public function decode(Document $collection, Document $document, array $selectio | |
| foreach ($relationships as $relationship) { | ||
| $key = $relationship['$id'] ?? ''; | ||
|
|
||
| if ( | ||
| \array_key_exists($key, (array)$document) | ||
| || \array_key_exists($this->adapter->filter($key), (array)$document) | ||
| ) { | ||
| if ($document->offsetExists($key) || $document->offsetExists($this->adapter->filter($key))) { | ||
| $value = $document->getAttribute($key); | ||
| $value ??= $document->getAttribute($this->adapter->filter($key)); | ||
| $document->removeAttribute($this->adapter->filter($key)); | ||
| $document->setAttribute($key, $value); | ||
| } | ||
| } | ||
|
|
||
| $attributes = \array_merge($attributes, $this->getInternalAttributes()); | ||
| foreach ($this->getInternalAttributes() as $attribute) { | ||
| if ($attribute['$id'] !== '$permissions') { | ||
| $attributes[] = new Document($attribute); | ||
| } | ||
| } | ||
|
|
||
| foreach ($attributes as $attribute) { | ||
| $key = $attribute['$id'] ?? ''; | ||
|
|
@@ -6392,10 +6392,11 @@ public function decode(Document $collection, Document $document, array $selectio | |
| $value = ($array) ? $value : [$value]; | ||
| $value = (is_null($value)) ? [] : $value; | ||
|
|
||
| foreach ($value as &$node) { | ||
| foreach (\array_reverse($filters) as $filter) { | ||
| foreach ($value as $k => $node) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove reference
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use a better name, $key, or something more descriptive if that collides
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to $index since $key is in use |
||
| foreach (array_reverse($filters) as $filter) { | ||
| $node = $this->decodeAttribute($filter, $node, $document, $key); | ||
| } | ||
| $value[$k] = $node; | ||
| } | ||
|
|
||
| if ( | ||
|
|
@@ -6426,7 +6427,11 @@ public function casting(Document $collection, Document $document): Document | |
|
|
||
| $attributes = $collection->getAttribute('attributes', []); | ||
|
|
||
| $attributes = \array_merge($attributes, $this->getInternalAttributes()); | ||
| foreach ($this->getInternalAttributes() as $attribute) { | ||
| if ($attribute['$id'] !== '$permissions') { | ||
| $attributes[] = new Document($attribute); | ||
| } | ||
| } | ||
|
|
||
| foreach ($attributes as $attribute) { | ||
| $key = $attribute['$id'] ?? ''; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.