Skip to content

Commit 2a18855

Browse files
authored
Update Hydrator.php
1 parent 6e59d45 commit 2a18855

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

src/Mapping/Hydration/Hydrator.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,42 @@
1414
*/
1515
class Hydrator implements HydratorInterface
1616
{
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+
1753
/**
1854
* @param $value
1955
* @param $object
@@ -23,11 +59,9 @@ class Hydrator implements HydratorInterface
2359
*/
2460
public function hydratePrimaryKey($value, $object)
2561
{
26-
$container = new Container();
27-
$reflection = new \ReflectionObject($object);
62+
$config = $this->getConfig($object);
2863

29-
/** @var Entity $config */
30-
$config = $container->get(get_class($object));
64+
$reflection = new \ReflectionObject($object);
3165

3266
foreach ($config->getFields() as $field) {
3367
if($field->isPrimaryKey()) {
@@ -49,10 +83,7 @@ public function hydratePrimaryKey($value, $object)
4983
*/
5084
public function hydrate(array $data, $object)
5185
{
52-
$container = new Container();
53-
54-
/** @var Entity $config */
55-
$config = $container->get(get_class($object));
86+
$config = $this->getConfig($object);
5687

5788
$reflectionObject = new \ReflectionObject($object);
5889
$objectProperties = $reflectionObject->getProperties();

0 commit comments

Comments
 (0)