1 | <?php |
||
7 | class ChoicesBuilder |
||
8 | { |
||
9 | /** |
||
10 | * @var EntityManager |
||
11 | */ |
||
12 | private $entityManager; |
||
13 | |||
14 | /** |
||
15 | * @param EntityManager $entityManager |
||
16 | */ |
||
17 | public function __construct(EntityManager $entityManager) |
||
21 | |||
22 | /** |
||
23 | * @param array|callable $choicesConfiguration |
||
24 | * |
||
25 | * @return array |
||
26 | * |
||
27 | * @throws \Exception |
||
28 | */ |
||
29 | public function build($choicesConfiguration) |
||
45 | |||
46 | /** |
||
47 | * @param array $choicesConfiguration |
||
48 | * |
||
49 | * @return array |
||
50 | * |
||
51 | * @throws \Exception |
||
52 | */ |
||
53 | private function getChoicesFromRepository(array $choicesConfiguration) |
||
81 | |||
82 | /** |
||
83 | * @deprecated Specifying repository as an object is deprecated and will not be supported since 1.0.0. Specify it by it's name instead. |
||
84 | * |
||
85 | * @param EntityRepository $repository |
||
86 | * |
||
87 | * @return EntityRepository |
||
88 | */ |
||
89 | private function getSpecifiedRepository(EntityRepository $repository) |
||
95 | |||
96 | /** |
||
97 | * Get all values available for this data field for consumption by |
||
98 | * the front-end in order to enable advanced UX functionality. |
||
99 | * |
||
100 | * @param EntityRepository $repository |
||
101 | * @param string $property |
||
102 | * @param null|string $sortOrder |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | private function getChoicesFromRepositoryForField(EntityRepository $repository, $property, $sortOrder = null) |
||
125 | |||
126 | /** |
||
127 | * @param EntityRepository $repository |
||
128 | * @param string $method |
||
129 | * |
||
130 | * @return array |
||
131 | * |
||
132 | * @throws \Exception |
||
133 | */ |
||
134 | private function getChoicesFromRepositoryWithMethod(EntityRepository $repository, $method) |
||
147 | |||
148 | /** |
||
149 | * @param callable $callable |
||
150 | * |
||
151 | * @return array |
||
152 | * |
||
153 | * @throws \Exception |
||
154 | */ |
||
155 | private function getChoicesFromCallable(callable $callable) |
||
164 | } |
||
165 |
The
EntityManager
might become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:If that code throws an exception and the
EntityManager
is closed. Any other code which depends on the same instance of theEntityManager
during this request will fail.On the other hand, if you instead inject the
ManagerRegistry
, thegetManager()
method guarantees that you will always get a usable manager instance.