1 | <?php |
||
18 | class WebcookCmsVoter implements VoterInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var View action. |
||
22 | */ |
||
23 | const ACTION_VIEW = 'view'; |
||
24 | |||
25 | /** |
||
26 | * @var Edit action |
||
27 | */ |
||
28 | const ACTION_INSERT = 'insert'; |
||
29 | |||
30 | /** |
||
31 | * @var Edit action |
||
32 | */ |
||
33 | const ACTION_EDIT = 'edit'; |
||
34 | |||
35 | /** |
||
36 | * @var Delete action |
||
37 | */ |
||
38 | const ACTION_DELETE = 'delete'; |
||
39 | |||
40 | /** |
||
41 | * Entity manager. |
||
42 | * |
||
43 | * @var EntityManager |
||
44 | */ |
||
45 | private $em; |
||
46 | |||
47 | /** |
||
48 | * Class constructor. |
||
49 | * |
||
50 | * @param EntityManager $em |
||
51 | */ |
||
52 | 41 | public function __construct(EntityManager $em) |
|
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | * |
||
60 | * @param string $attribute |
||
61 | * |
||
62 | * @return bool |
||
63 | */ |
||
64 | 39 | public function supportsAttribute($attribute) |
|
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | * |
||
77 | * @param string $class |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | 1 | public function supportsClass($class) |
|
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | * |
||
89 | * @param TokenInterface $token |
||
90 | * @param string $resource |
||
91 | * @param array $attributes |
||
92 | * |
||
93 | * @return int |
||
94 | */ |
||
95 | 40 | public function vote(TokenInterface $token, $resource, array $attributes) |
|
122 | } |
||
123 |
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.