14
14
*/
15
15
class Hydrator implements HydratorInterface
16
16
{
17
+ private $ configs = [];
18
+ private $ inputFilters = [];
19
+
20
+ /**
21
+ * @param $object
22
+ * @return null|Entity
23
+ * @throws \Zend\Cache\Exception\ExceptionInterface
24
+ * @throws \Zend\EntityMapper\Config\Container\Exceptions\ItemNotFoundException
25
+ */
26
+ private function getConfig ($ object )
27
+ {
28
+ $ config = null ;
29
+
30
+ $ class = $ object ;
31
+ if (is_object ($ object )) {
32
+ $ class = get_class ($ object );
33
+ }
34
+
35
+ if (isset ($ this ->configs [$ class ])) {
36
+ /** @var Entity $config */
37
+ $ config = $ this ->configs [$ class ];
38
+ }
39
+ else
40
+ {
41
+ $ container = new Container ();
42
+
43
+ /** @var Entity $config */
44
+ $ config = $ container ->get ($ class );
45
+
46
+ $ this ->configs [$ class ] = $ config ;
47
+ }
48
+
49
+ return $ config ;
50
+ }
51
+
52
+
17
53
/**
18
54
* @param $value
19
55
* @param $object
@@ -23,11 +59,9 @@ class Hydrator implements HydratorInterface
23
59
*/
24
60
public function hydratePrimaryKey ($ value , $ object )
25
61
{
26
- $ container = new Container ();
27
- $ reflection = new \ReflectionObject ($ object );
62
+ $ config = $ this ->getConfig ($ object );
28
63
29
- /** @var Entity $config */
30
- $ config = $ container ->get (get_class ($ object ));
64
+ $ reflection = new \ReflectionObject ($ object );
31
65
32
66
foreach ($ config ->getFields () as $ field ) {
33
67
if ($ field ->isPrimaryKey ()) {
@@ -49,10 +83,7 @@ public function hydratePrimaryKey($value, $object)
49
83
*/
50
84
public function hydrate (array $ data , $ object )
51
85
{
52
- $ container = new Container ();
53
-
54
- /** @var Entity $config */
55
- $ config = $ container ->get (get_class ($ object ));
86
+ $ config = $ this ->getConfig ($ object );
56
87
57
88
$ reflectionObject = new \ReflectionObject ($ object );
58
89
$ objectProperties = $ reflectionObject ->getProperties ();
0 commit comments