Skip to content

Commit 06837ae

Browse files
committed
Fix order of operations in serialization and deserialization
1 parent 29af798 commit 06837ae

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/Models/ActiveDirectory/Entry.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected function convertAttributesForJson(array $attributes = []): array
143143
$attributes = parent::convertAttributesForJson($attributes);
144144

145145
// If the model has a SID set, we need to convert it to its
146-
// string format, due to it being in binary. Otherwise
146+
// string format, due to it being in binary. Otherwise,
147147
// we will receive a JSON serialization exception.
148148
if (isset($attributes[$this->sidKey])) {
149149
$attributes[$this->sidKey] = [$this->getConvertedSid(
@@ -161,15 +161,6 @@ protected function convertAttributesFromJson(array $attributes = []): array
161161
{
162162
$attributes = parent::convertAttributesFromJson($attributes);
163163

164-
// Here we are converting the model's GUID and SID attributes
165-
// back to their original values from serialization, so that
166-
// their original value may be used and compared against.
167-
if (isset($attributes[$this->guidKey])) {
168-
$attributes[$this->guidKey] = [$this->getBinaryGuid(
169-
Arr::first($attributes[$this->guidKey])
170-
)];
171-
}
172-
173164
if (isset($attributes[$this->sidKey])) {
174165
$attributes[$this->sidKey] = [$this->getBinarySid(
175166
Arr::first($attributes[$this->sidKey])

src/Models/Concerns/HasAttributes.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ public function attributesToArray(): array
113113
*/
114114
public function arrayToOriginal(array $attributes): array
115115
{
116-
return $this->decodeAttributes(
117-
$this->convertAttributesFromJson($attributes)
118-
);
116+
$attributes = $this->decodeAttributes($attributes);
117+
118+
return $this->convertAttributesFromJson($attributes);
119119
}
120120

121121
/**
@@ -125,9 +125,9 @@ public function arrayToAttributes(array $attributes): array
125125
{
126126
$attributes = $this->restoreDateAttributesFromArray($attributes);
127127

128-
return $this->decodeAttributes(
129-
$this->convertAttributesFromJson($attributes)
130-
);
128+
$attributes = $this->decodeAttributes($attributes);
129+
130+
return $this->convertAttributesFromJson($attributes);
131131
}
132132

133133
/**

src/Models/Model.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,15 @@ protected function convertAttributesForJson(array $attributes = []): array
527527
*/
528528
protected function convertAttributesFromJson(array $attributes = []): array
529529
{
530+
// Here we are converting the model's GUID and SID attributes
531+
// back to their original values from serialization, so that
532+
// their original value may be used and compared against.
533+
if (isset($attributes[$this->guidKey])) {
534+
$attributes[$this->guidKey] = [$this->getBinaryGuid(
535+
Arr::first($attributes[$this->guidKey])
536+
)];
537+
}
538+
530539
return $attributes;
531540
}
532541

0 commit comments

Comments
 (0)