Giter VIP home page Giter VIP logo

Comments (22)

armetiz avatar armetiz commented on July 18, 2024

Good proposition.
enabled booleanNode should have "true" as default value.

from doctrinebundle.

beberlei avatar beberlei commented on July 18, 2024

I think filters should be disabled by default, otherwise the proposition is good. You can implement this and send a PR.

Whats your take @asm89 ?

from doctrinebundle.

Burgov avatar Burgov commented on July 18, 2024

exactly how could you force the filter to be abled using the container builder?

right now i'm trying this in a compiler pass, which i could port to this bundle once I get it working

        $container->getDefinition('doctrine.orm.default_configuration')
            ->addMethodCall('addFilter', array('filtername', 'classname'))
        ;
        $container->getDefinition('doctrine.orm.default_entity_manager')
            ->addMethodCall('getFilters', array())
            ->addMethodCall('enable', array('filtername'))
        ;

but that doesn't result in the desired code in the container class

        $instance->getFilters();
        $instance->enable('filtername');

rather than

        $instance->getFilters()->enable('filtername');

from doctrinebundle.

asm89 avatar asm89 commented on July 18, 2024

Looks fine imo. I agree with @beberlei that filters should be disabled by default, because I think there are a lot of use cases where filters need additional parameters in order to work properly.

from doctrinebundle.

yoannch avatar yoannch commented on July 18, 2024

I agree with @beberlei and @asm89 : this boolean should have a false default value.

@Burgov I'm investigating right now on how to do that too, if you have any suggestions or ideas, feel free to mail me.

from doctrinebundle.

Burgov avatar Burgov commented on July 18, 2024

I couldn't think of a way without changing Doctrine ORM code, for example a third optional boolean argument to addFilter, or an en-/disableFilter method on the entitymanager...

from doctrinebundle.

stof avatar stof commented on July 18, 2024

@Burgov I can look at it at the end of the week if you have issues implementing it

from doctrinebundle.

Burgov avatar Burgov commented on July 18, 2024

@stof that'd be great. I'd write a PR if I knew how to do this. Unfortunately I'll be out of the country next week, so I won't be able to make any PR's soon

from doctrinebundle.

yoannch avatar yoannch commented on July 18, 2024

@stof did you have some time to explore this issues? I'm still blocking on the same issue as @Burgov ... if you have any tips, you're welcome!

from doctrinebundle.

stof avatar stof commented on July 18, 2024

I had no time at all for the Symfony2 community this weekend.

from doctrinebundle.

yoannch avatar yoannch commented on July 18, 2024

I found a solution! I implement it now, make tests and send you the PR as all tests will pass.

I just have a question about the configuration.

I first made a proposal as follow :

doctrine:
    ...
    orm:
        filters:
            my_first_filter:
                class: 'Fully\Qualified\Class\Name'
                enabled: true
            my_second_filter:
                class: 'Fully\Qualified\Class\Name2'
                enabled: true

I think that will work for the default entity manager, but if someone has different entity managers, he may want to have different filters for each of his entity managers right?

So I was thinking of the following conf :

doctrine:
    ...
    orm:
        filters:
            my_first_filter:
                class: 'Fully\Qualified\Class\Name'
                enabled: true
            my_second_filter:
                class: 'Fully\Qualified\Class\Name2'
                enabled: true
        entity_managers:
            em1:
                filters:
                    my_em1_filter:
                        class: 'Fully\Qualified\Class\Name'
                        enable: true
            em2:
                filters:
                    my_first_em2_filter:
                        class: 'Fully\Qualified\Class\Name'
                        enabled: true
                    my_scnd_em2_filter:
                        class: 'Fully\Qualified\Class\Name'
                        enabled: true

or do you think the following conf will be better :

doctrine:
    ...
    orm:
        entity_managers:
            default:
                filters:
                    my_first_filter:
                        class: 'Fully\Qualified\Class\Name'
                        enabled: true
                    my_second_filter:
                        class: 'Fully\Qualified\Class\Name2'
                        enabled: true
            em1:
                filters:
                    my_em1_filter:
                        class: 'Fully\Qualified\Class\Name'
                        enable: true
            em2:
                filters:
                    my_first_em2_filter:
                        class: 'Fully\Qualified\Class\Name'
                        enabled: true
                    my_scnd_em2_filter:
                        class: 'Fully\Qualified\Class\Name'
                        enabled: true

?

from doctrinebundle.

stof avatar stof commented on July 18, 2024

it should be done at the em level, like for DQL functions

from doctrinebundle.

stof avatar stof commented on July 18, 2024

so your last example (and the first one will correspond to the short syntax which is rewritten)

from doctrinebundle.

yoannch avatar yoannch commented on July 18, 2024

Ok, thanks for your advice. So I implement it to handle both the last example and the short syntax one (the first I gave).

from doctrinebundle.

stof avatar stof commented on July 18, 2024

No, you implement the last example and you add the needed key in the list of rewritten keys for the short syntax. Look at how it is handled

from doctrinebundle.

stof avatar stof commented on July 18, 2024

@beberlei @asm89 does it make sense to give the possibility to enable a sql filter through the config ? It would assume that the sql filter can work without any parameters.

from doctrinebundle.

asm89 avatar asm89 commented on July 18, 2024

Yes. For example a SoftDeleteFilter could query for and <alias>.deleted = 0. There is no need to configure the parameters.

from doctrinebundle.

stof avatar stof commented on July 18, 2024

I finally took some time (over my sleeping time obviously) to implement it

from doctrinebundle.

Burgov avatar Burgov commented on July 18, 2024

Very nice! Need to remember these configurator classes, I can imagine it'll come in handy more often.

from doctrinebundle.

stof avatar stof commented on July 18, 2024

@Burgov in most cases, they are overkill. The best way to see this is that I never saw a use case for them until yesterday

from doctrinebundle.

julesbou avatar julesbou commented on July 18, 2024

@stof Thanks for your time, for my part i've always had a big use case for this feature, restrict user_id on a multi-user product (SAAS).

from doctrinebundle.

yoannch avatar yoannch commented on July 18, 2024

@stof thank you very much for your time, I've been (and still am) overloaded theses weeks, and couldn't deal with it.

from doctrinebundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.