-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManagerProvider.php
90 lines (81 loc) · 2.24 KB
/
ManagerProvider.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/*
* This file is part of the Elcodi package.
*
* Copyright (c) 2014-2016 Elcodi Networks S.L.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <yuhu@mmoreram.com>
* @author Aldo Chiecchia <zimage@tiscali.it>
* @author Elcodi Team <tech@elcodi.com>
*/
namespace Elcodi\Component\Core\Services;
use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
* Class ManagerProvider.
*/
class ManagerProvider
{
/**
* @var AbstractManagerRegistry
*
* Manager
*/
private $manager;
/**
* @var ParameterBag
*
* Parameter bag
*/
private $parameterBag;
/**
* Construct method.
*
* @param AbstractManagerRegistry $manager Manager
* @param ParameterBag $parameterBag Parameter bag
*/
public function __construct(
AbstractManagerRegistry $manager,
ParameterBag $parameterBag
) {
$this->manager = $manager;
$this->parameterBag = $parameterBag;
}
/**
* Given an entity namespace, return associated object Manager.
*
* @param string $entityNamespace Entity Namespace
*
* @return ObjectManager|null Object manager
*/
public function getManagerByEntityNamespace($entityNamespace)
{
return $this
->manager
->getManagerForClass($entityNamespace);
}
/**
* Given an entity parameter definition, returns associated object Manager.
*
* This method is only useful when your entities namespaces are defined as
* a parameter, very useful when you want to provide a way of overriding
* entities easily
*
* @param string $entityParameter Entity Parameter
*
* @return ObjectManager|null Object manager
*/
public function getManagerByEntityParameter($entityParameter)
{
$entityNamespace = $this
->parameterBag
->get($entityParameter);
return $this->getManagerByEntityNamespace($entityNamespace);
}
}