/
HydratorPool.php
51 lines (45 loc) · 1.09 KB
/
HydratorPool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\EntityManager;
use Magento\Framework\ObjectManagerInterface;
/**
* Class HydratorPool
*/
class HydratorPool
{
/**
* @var array|\string[]
*/
private $hydrators;
/**
* @var ObjectManagerInterface
*/
protected $objectManager;
/**
* HydratorPool constructor.
* @param ObjectManagerInterface $objectManager
* @param string[] $hydrators
*/
public function __construct(
ObjectManagerInterface $objectManager,
$hydrators = []
) {
$this->objectManager = $objectManager;
$this->hydrators = $hydrators;
}
/**
* @param string $entityType
* @return EntityHydratorInterface
*/
public function getHydrator($entityType)
{
if (isset($this->hydrators[$entityType])) {
return $this->objectManager->get($this->hydrators[$entityType]);
} else {
return $this->objectManager->get(EntityHydratorInterface::class);
}
}
}