1 | <?php |
||
12 | class SettingsManager implements ParameterBagInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var EntityManager |
||
16 | */ |
||
17 | protected $entityManager; |
||
18 | |||
19 | /** |
||
20 | * @var SettingRepository |
||
21 | */ |
||
22 | protected $repository; |
||
23 | |||
24 | /** |
||
25 | * Parameter storage. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $settings; |
||
30 | |||
31 | /** |
||
32 | * Is the class initialized |
||
33 | * |
||
34 | * @var bool |
||
35 | */ |
||
36 | protected $isInitialized = false; |
||
37 | |||
38 | /** |
||
39 | * @param EntityManager $entityManager |
||
40 | * @param SettingRepository $repository |
||
41 | */ |
||
42 | 11 | public function __construct($entityManager, $repository) |
|
47 | |||
48 | /** |
||
49 | * Initialize the settings |
||
50 | */ |
||
51 | 5 | protected function initialize() |
|
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 1 | public function clear() |
|
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | 3 | public function add(array $parameters) |
|
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | 5 | public function all() |
|
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | 2 | public function get($name, $defaultValue = null) |
|
114 | |||
115 | /** |
||
116 | * Store a setting |
||
117 | * |
||
118 | * @param string $name |
||
119 | * @param mixed $value |
||
120 | * @param bool $isEditable |
||
121 | * @return $this |
||
122 | */ |
||
123 | 4 | public function set($name, $value, $isEditable = false) |
|
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | 5 | public function has($name) |
|
157 | |||
158 | /** |
||
159 | * {@inheritdoc} |
||
160 | */ |
||
161 | 1 | public function resolve() |
|
165 | |||
166 | /** |
||
167 | * {@inheritdoc} |
||
168 | */ |
||
169 | 1 | public function resolveValue($value) |
|
173 | |||
174 | /** |
||
175 | * {@inheritdoc} |
||
176 | */ |
||
177 | 1 | public function escapeValue($value) |
|
181 | |||
182 | /** |
||
183 | * {@inheritdoc} |
||
184 | */ |
||
185 | 1 | public function unescapeValue($value) |
|
189 | |||
190 | /** |
||
191 | * {@inheritdoc} |
||
192 | */ |
||
193 | public function remove($name) |
||
197 | } |
||
198 |
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.