Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to enable filters #750

Open
darckking opened this issue Dec 15, 2023 · 1 comment
Open

Add possibility to enable filters #750

darckking opened this issue Dec 15, 2023 · 1 comment

Comments

@darckking
Copy link

Currently the Doctrine filters can be added to EntityManager's Configuration object by providing them in configuration array as:

'filters' => [
    'filter-name' => 'FilterClass'
]

However, they're disabled by default and need to be explicitly enabled by calling $entityManager->getFilters()->enable('filter-name')
Usually, I'd put filters initialization in Module, that implements BootstrapListenerInterface, inside the onBootstrap() function but if application uses laminas-cli this function won't be called as laminas-cli doesn't lift the whole app.

In ideal scenario filters should be configured and enabled in one place and it should work for both web and cli. Just like it works in
Doctrine Bundle for Symfony.

filters:
    filter-name:
        class: FilterClass
        enabled: true

I looked in EntityManager internals and the $filterCollection property is initialized only on the first call of getFilters(), hence filters can be enabled only after EntityManager was instantiated.

So what's the opinion about it, should it be in scope of DoctrineORMModule to enable filters like Doctrine Bundle for Symfony does or it's up to users to enable them ?

@TomHAnderson
Copy link
Member

Filters in DoctrineORMModule configuration are passed on through to the ORM. Avoiding any work on the EntityManager before it is explicitly called, such as $entityManager->getFilters()->enable('filter') is avoided e.g. https://www.doctrine-project.org/projects/doctrine-orm/en/2.17/reference/filters.html#disabling-enabling-filters-and-setting-parameters

I think the Laminas way to do this is to subscribe to a modules post load function to do fine-grained configuration. I think this is an interesting question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants