Skip to content

Commit 4938f73

Browse files
authored
Merge pull request #8 from wol-soft/SkipSerializationOfInternalProperties
Skip the serialization of internal properties
2 parents 491716b + 5a4940e commit 4938f73

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/Traits/SerializableTrait.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
trait SerializableTrait
1717
{
18-
private static $customSerializer = [];
18+
private static $_customSerializer = [];
1919

2020
/**
2121
* Get a JSON representation of the current state
@@ -61,10 +61,9 @@ public function toArray(array $except = [], int $depth = 512)
6161

6262
$depth--;
6363
$modelData = [];
64-
array_push($except, 'rawModelDataInput', 'errorRegistry', 'customSerializer');
6564

6665
foreach (get_class_vars(get_class($this)) as $key => $value) {
67-
if (in_array($key, $except)) {
66+
if (in_array($key, $except) || strstr($key, '_') !== false) {
6867
continue;
6968
}
7069

@@ -124,15 +123,15 @@ private function evaluateAttribute($attribute, int $depth, array $except)
124123
}
125124

126125
private function getCustomSerializerMethod(string $property) {
127-
if (isset(self::$customSerializer[$property])) {
128-
return self::$customSerializer[$property];
126+
if (isset(self::$_customSerializer[$property])) {
127+
return self::$_customSerializer[$property];
129128
}
130129

131130
$customSerializer = 'serialize' . ucfirst($property);
132131
if (!method_exists($this, $customSerializer)) {
133132
$customSerializer = false;
134133
}
135134

136-
return self::$customSerializer[$property] = $customSerializer;
135+
return self::$_customSerializer[$property] = $customSerializer;
137136
}
138137
}

0 commit comments

Comments
 (0)