| @@ 28-64 (lines=37) @@ | ||
| 25 | * @license X11 {@link http://opensource.org/licenses/mit-license.php} |
|
| 26 | * @see ClientPooler |
|
| 27 | */ |
|
| 28 | class ContainerModelLayerPooler extends ModelLayerPooler implements ServiceMapInterface |
|
| 29 | { |
|
| 30 | private $serviceMap = []; |
|
| 31 | /** @var PsrContainerInterface|ContainerInterface */ |
|
| 32 | private $container; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * {@inheritdoc} |
|
| 36 | */ |
|
| 37 | public function addModelToServiceMapping($class, $serviceId) |
|
| 38 | { |
|
| 39 | $this->serviceMap[$class] = $serviceId; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * {@inheritdoc} |
|
| 44 | */ |
|
| 45 | protected function createClient($class) |
|
| 46 | { |
|
| 47 | if (array_key_exists($class, $this->serviceMap)) { |
|
| 48 | return $this->container->get($this->serviceMap[$class]); |
|
| 49 | } |
|
| 50 | ||
| 51 | return parent::createClient($class); |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * @param PsrContainerInterface|ContainerInterface $container |
|
| 56 | */ |
|
| 57 | public function setContainer($container) |
|
| 58 | { |
|
| 59 | if (!($container instanceof PsrContainerInterface) && !($container instanceof ContainerInterface)) { |
|
| 60 | throw new \InvalidArgumentException( |
|
| 61 | '$contaner should be instance of Symfony\Component\DependencyInjection\ContainerInterface or Psr\Container\ContainerInterface' |
|
| 62 | ); |
|
| 63 | } |
|
| 64 | $this->container = $container; |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||
| @@ 27-63 (lines=37) @@ | ||
| 24 | * @license X11 {@link http://opensource.org/licenses/mit-license.php} |
|
| 25 | * @see Extension |
|
| 26 | */ |
|
| 27 | class ContainerModelPooler extends ModelPooler implements ServiceMapInterface |
|
| 28 | { |
|
| 29 | private $serviceMap = []; |
|
| 30 | /** @var PsrContainerInterface|ContainerInterface */ |
|
| 31 | private $container; |
|
| 32 | ||
| 33 | /** |
|
| 34 | * {@inheritdoc} |
|
| 35 | */ |
|
| 36 | public function addModelToServiceMapping($class, $serviceId) |
|
| 37 | { |
|
| 38 | $this->serviceMap[$class] = $serviceId; |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * {@inheritdoc} |
|
| 43 | */ |
|
| 44 | protected function createClient($class) |
|
| 45 | { |
|
| 46 | if (array_key_exists($class, $this->serviceMap)) { |
|
| 47 | return $this->container->get($this->serviceMap[$class]); |
|
| 48 | } |
|
| 49 | ||
| 50 | return parent::createClient($class); |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * @param PsrContainerInterface|ContainerInterface $container |
|
| 55 | */ |
|
| 56 | public function setContainer($container) |
|
| 57 | { |
|
| 58 | if (!($container instanceof PsrContainerInterface) && !($container instanceof ContainerInterface)) { |
|
| 59 | throw new \InvalidArgumentException( |
|
| 60 | '$contaner should be instance of Symfony\Component\DependencyInjection\ContainerInterface or Psr\Container\ContainerInterface' |
|
| 61 | ); |
|
| 62 | } |
|
| 63 | $this->container = $container; |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||