Coder Social home page Coder Social logo

Comments (7)

dunglas avatar dunglas commented on July 28, 2024

This feature has been partially contributed by @amenophis in #44

It can be features 2 + 3 + 4 :)

from core.

theofidry avatar theofidry commented on July 28, 2024

Ok, just waiting for you to finish the doc before closing this ticket then.

from core.

theofidry avatar theofidry commented on July 28, 2024

@dunglas since the PR has been merged and from what I see all the features has been added by now but I do not see it in the doc though.

from core.

theofidry avatar theofidry commented on July 28, 2024

I was thinking of updating the doc. Should I put it in a dedicated chapter or to append it in an existing one?

from core.

theofidry avatar theofidry commented on July 28, 2024

Update on the issue:

1 +3 is already handled and documented here.

1 + 2 is possible be requires to declare a custom DataProvider like the following:

resource.dummy.data_provider:
    class:    Dunglas\ApiBundle\Doctrine\Orm\DataProvider
    arguments:
        - @doctrine
        - %api.collection.order%
        - %api.collection.pagination.page_parameter_name%
        - %api.collection.pagination.items_per_page.number%
        - %api.collection.pagination.items_per_page.enable_client_request%
        - %api.collection.pagination.items_per_page.parameter_name%

resource.dummy:
    parent:       api.resource
    arguments:    [ AppBundle\Entity\Dummy, @resource.dummy.data_provider ]

The above use the default parameters specified in the config, to override them is just needed to put the wished value.

But doing so is quite verbose and tedious if one want to do so for several entities. At the moment, the simpliest way I've found is to roll out my own DataProvider, adding some initX methods to play with the parameters and declaring it as abstract. Then I just have to declare a new data provider for my resource using this new data provider as a parent and doing calls to change only the parameters wished:

api.extended_data_provider:
    class:    DataProvider\ExtendedDataProvider
    abstract: true
    arguments:
        - @doctrine
        - %api.collection.order%
        - %api.collection.pagination.page_parameter_name%
        - %api.collection.pagination.items_per_page.number%
        - %api.collection.pagination.items_per_page.enable_client_request%
        - %api.collection.pagination.items_per_page.parameter_name%

resource.dummy.data_provider:
    parent: api.extended_data_provider
    calls:
        -   [ initEnableClientRequestItemsPerPage, [ true ] ]
    tags:   [ { name: api.data_provider } ]

resource.dummy:
    parent:       api.resource
    arguments:    [ AppBundle\Entity\Dummy, @resource.dummy.data_provider ]

In both cases I'm quite unhappy with the process: it's too much for such simple task. Would it be possible to add directly those initX methods in the bundle DataProvider? Unless you see another way, that would imply to also add an abstract service, but at least it 1 + 2 does not feel like hacking the bundle and risking to break everything at every change of the bundle DataProvider anymore.

In both cases, since this is a complete and concrete use case, a dedicated documentation should be available.

To recap:

  • Dedicated documentation for the four use cases
  • Decide on the approach to handle the 1 + 2 use case in a better way

from core.

theofidry avatar theofidry commented on July 28, 2024

Goes with #131

from core.

dunglas avatar dunglas commented on July 28, 2024

Done in v2.

from core.

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.