tobyzerner / json-api-server

A JSON:API server implementation in PHP.
https://tobyzerner.github.io/json-api-server/
MIT License
63 stars 21 forks source link

Make HasVisibility closure signature identical with/without model data #82

Closed davwheat closed 10 months ago

davwheat commented 10 months ago

At the moment, if there is model data available, a closure provided to the HasVisibility modifier will receive both the model and the API context, while no model data results in only the API context.

Right now, we can't define the closure as fn (Context $c) => ... since the model, if available, is set to the first param.

Instead of having a throwaway parameter to the closure, could we swap these params so that the context is always first and the model is second, if available? It would simplify the function signatures a lot as my use case doesn't have differing visibility of models per-user, for example.

davwheat commented 10 months ago

Ah, yeah, no this would break the ability to directly parse Laravel's can(). Nevermind then!