Commit 6cd2150
authored
Fix security context missing in Doctrine entity listeners after kernel reboot (#236)
_getEntityManager() persisted the EntityManager as a permanent service, so it
was carried across kernel reboots and re-injected into the freshly booted
container. An EntityManager cannot survive a reboot: its ListenersInvoker is
bound (readonly) to the container it was built in, so lazy entity listeners
resolve dependencies like security.token_storage from that now-stale
container. The logged-in user was therefore invisible inside the listener
while visible in the controller. In pure Symfony (WebTestCase) there is no
reboot, one container, so listener and controller share the same context.
Fix: resolve the EntityManager fresh from the current container on every call
instead of caching it as a permanent service. Only doctrine.dbal.default_connection
stays persistent, which is what keeps the open test transaction alive across
reboots; the freshly rebuilt EntityManager runs on top of it, with every
dependency (security included) wired to the current request. This also keeps
the module's Doctrine helpers and the application on a single identity map,
matching pure Symfony.
Fixes #34, #90, #150, #1511 parent 81c0365 commit 6cd2150
1 file changed
Lines changed: 15 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
276 | 286 | | |
277 | 287 | | |
278 | 288 | | |
279 | 289 | | |
280 | 290 | | |
281 | 291 | | |
282 | | - | |
283 | | - | |
| 292 | + | |
284 | 293 | | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 294 | + | |
| 295 | + | |
289 | 296 | | |
290 | 297 | | |
291 | 298 | | |
292 | | - | |
| 299 | + | |
293 | 300 | | |
294 | 301 | | |
295 | 302 | | |
| |||
0 commit comments