cakephp / authorization

PSR7 Middleware for authorization
MIT License
76 stars 46 forks source link

3.next: add DIC support to OrmResolver #275

Closed LordSimal closed 8 months ago

LordSimal commented 8 months ago

This is a proposal initiated by @jamisonbryant to make at least the OrmResolver more DI aware.

Instead of having to pass on services to ->can() etc. one can easily inject the needed services into the policies which actually need them to do whatever logic is required to authorize the current user on the given action.

To get this working from a user perspective, all they would have to adjust in their Application::getAuthorizationService method is

$ormResolver = new OrmResolver();

to

$ormResolver = new OrmResolver('App', [], $this->getContainer());

After that all policies retrieved by the OrmResolver can leverage constructor injection.

If we want to go this way then we should also make the MapResolver DI aware as well.

markstory commented 8 months ago

Seems like a good change to me.

LordSimal commented 8 months ago

@jamisonbryant anything to add from your side? If not I'd merge this and add support for DI to the MapResolver as well

jamisonbryant commented 8 months ago

No, this looks good to me. Well done!