-
Notifications
You must be signed in to change notification settings - Fork 46
Description
I recently installed this package to slowly enable authorization for my project. Installing it and configuring the basics worked perfectly fine. However, I'm a bit struggling with implementing the policy/entity relation using the OrmResolver.
I'm not sure if I'm doing something wrong here, but it seems that placing entities/policies in sub-directories doesn't seem to work for me.
My folder structure:
src/
Model/
Entity/
SubDir/
User.php
Policy/
SubDir/
UserPolicy.php
I'm using the OrmResolver to automatically resolve the entity/policy relation as my project has a lot of entities (~170). Using the MapResolver to map the relations manually would be quite an inconvenience.
I noticed during debugging that my issue mainly lies within the OrmResolver::getEntityPolicy or App::className.
The first function seems to prepare the data for App::className to resolve the Policy based on an entity instance/class.
It resolves to something like this:
App::className('App.SubDir\User', 'Policy', 'Policy');
// = null
The implementation of App::className has an early return on the first line (str_contains($class, '\\')) which stops the search directly.
If the usage would be changed to the following, the App::className would be working as intended.
App::className('App.SubDir/User', 'Policy', 'Policy'); // Notice the '\' being changed to '/'.
// = 'App\Policy\SubDir\UserPolicy'
I can't tell if this is an issue within the core cakephp function, or due to the preparation done by OrmResolver::getEntityPolicy.
Does anyone know if this is a simple misconfiguration on my end, a bug in this project or a bug in the cakephp project?