| 1 | <?php |
||
| 12 | abstract class BaseFilter extends AbstractType implements BaseFilterInterface |
||
| 13 | { |
||
| 14 | protected $em; |
||
| 15 | protected $request; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param EntityManager $em |
||
| 19 | * @param Request $request |
||
| 20 | */ |
||
| 21 | public function __construct(EntityManager $em, Request $request) |
||
| 26 | |||
| 27 | public function buildQuery(QueryBuilder $qb, array $parameters) |
||
| 30 | |||
| 31 | public function buildForm(FormBuilderInterface $builder, array $options) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * {@inheritdoc} |
||
| 37 | */ |
||
| 38 | public function configureOptions(OptionsResolver $resolver) |
||
| 48 | |||
| 49 | public function getName() |
||
| 52 | } |
||
| 53 |
The
EntityManagermight 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
EntityManageris closed. Any other code which depends on the same instance of theEntityManagerduring 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.