@@ -55,45 +55,14 @@ public static function hydrate($objects, $values, $properties, $value, $wakeups)
55
55
56
56
public static function getHydrator ($ class )
57
57
{
58
- if ('stdClass ' === $ class ) {
59
- return self ::$ hydrators [$ class ] = static function ($ properties , $ objects ) {
60
- foreach ($ properties as $ name => $ values ) {
61
- foreach ($ values as $ i => $ v ) {
62
- $ objects [$ i ]->$ name = $ v ;
63
- }
64
- }
65
- };
66
- }
67
-
68
- if (!class_exists ($ class ) && !interface_exists ($ class , false ) && !trait_exists ($ class , false )) {
69
- throw new ClassNotFoundException ($ class );
70
- }
71
- $ classReflector = new \ReflectionClass ($ class );
72
-
73
- if (!$ classReflector ->isInternal ()) {
74
- return self ::$ hydrators [$ class ] = (self ::$ hydrators ['stdClass ' ] ?? self ::getHydrator ('stdClass ' ))->bindTo (null , $ class );
75
- }
76
-
77
- if ($ classReflector ->name !== $ class ) {
78
- return self ::$ hydrators [$ classReflector ->name ] ?? self ::getHydrator ($ classReflector ->name );
79
- }
80
-
81
58
switch ($ class ) {
82
- case 'ArrayIterator ' :
83
- case 'ArrayObject ' :
84
- $ constructor = \Closure::fromCallable ([$ classReflector ->getConstructor (), 'invokeArgs ' ]);
85
-
86
- return self ::$ hydrators [$ class ] = static function ($ properties , $ objects ) use ($ constructor ) {
59
+ case 'stdClass ' :
60
+ return self ::$ hydrators [$ class ] = static function ($ properties , $ objects ) {
87
61
foreach ($ properties as $ name => $ values ) {
88
- if ("\0" !== $ name ) {
89
- foreach ($ values as $ i => $ v ) {
90
- $ objects [$ i ]->$ name = $ v ;
91
- }
62
+ foreach ($ values as $ i => $ v ) {
63
+ $ objects [$ i ]->$ name = $ v ;
92
64
}
93
65
}
94
- foreach ($ properties ["\0" ] ?? [] as $ i => $ v ) {
95
- $ constructor ($ objects [$ i ], $ v );
96
- }
97
66
};
98
67
99
68
case 'ErrorException ' :
@@ -122,6 +91,38 @@ public static function getHydrator($class)
122
91
};
123
92
}
124
93
94
+ if (!class_exists ($ class ) && !interface_exists ($ class , false ) && !trait_exists ($ class , false )) {
95
+ throw new ClassNotFoundException ($ class );
96
+ }
97
+ $ classReflector = new \ReflectionClass ($ class );
98
+
99
+ switch ($ class ) {
100
+ case 'ArrayIterator ' :
101
+ case 'ArrayObject ' :
102
+ $ constructor = \Closure::fromCallable ([$ classReflector ->getConstructor (), 'invokeArgs ' ]);
103
+
104
+ return self ::$ hydrators [$ class ] = static function ($ properties , $ objects ) use ($ constructor ) {
105
+ foreach ($ properties as $ name => $ values ) {
106
+ if ("\0" !== $ name ) {
107
+ foreach ($ values as $ i => $ v ) {
108
+ $ objects [$ i ]->$ name = $ v ;
109
+ }
110
+ }
111
+ }
112
+ foreach ($ properties ["\0" ] ?? [] as $ i => $ v ) {
113
+ $ constructor ($ objects [$ i ], $ v );
114
+ }
115
+ };
116
+ }
117
+
118
+ if (!$ classReflector ->isInternal ()) {
119
+ return self ::$ hydrators [$ class ] = (self ::$ hydrators ['stdClass ' ] ?? self ::getHydrator ('stdClass ' ))->bindTo (null , $ class );
120
+ }
121
+
122
+ if ($ classReflector ->name !== $ class ) {
123
+ return self ::$ hydrators [$ classReflector ->name ] ?? self ::getHydrator ($ classReflector ->name );
124
+ }
125
+
125
126
$ propertySetters = [];
126
127
foreach ($ classReflector ->getProperties () as $ propertyReflector ) {
127
128
if (!$ propertyReflector ->isStatic ()) {
0 commit comments