Skip to content

Support sub-directory entities and tables in OrmResolver#331

Open
dereuromark wants to merge 2 commits into
3.xfrom
fix-orm-resolver-subdir
Open

Support sub-directory entities and tables in OrmResolver#331
dereuromark wants to merge 2 commits into
3.xfrom
fix-orm-resolver-subdir

Conversation

@dereuromark
Copy link
Copy Markdown
Member

Closes #315.

Background

The OrmResolver already converts the namespace segment of a resource class from backslashes to forward slashes before handing it to App::className():

$namespace = str_replace('\\', '/', substr($class, 0, (int)strpos($class, $entityNamespace)));

…but the name segment is left as-is. For a class like TestApp\Model\Entity\SubDir\Widget the resolver therefore passes App.SubDir\Widget to App::className(). App::className() short-circuits on any embedded backslash and returns null, so a MissingPolicyException is thrown even when App\Policy\SubDir\WidgetPolicy exists at the expected location.

The namespace side of this conversion was added intentionally — so partial sub-directory support is already present. This change finishes the job for the name half.

Change

Apply the same str_replace('\\', '/', …) to the name segment in both getEntityPolicy() and getRepositoryPolicy().

Note on previous discussion

Issue #315 was closed as "use FQCN" — that workaround still works (via MapResolver registration), and consumers who want manual control can keep doing it. This PR is additive: nothing changes for flat layouts, and the same convention App\Policy\SubDir\WidgetPolicy for App\Model\Entity\SubDir\Widget simply starts working. If maintainers prefer to keep the convention-based resolver flat-only, feel free to close.

Verification

  • composer test — 142 tests, 291 assertions (was 140 / 289). 2 new tests, one entity and one table, both with a SubDir/Widget(s) fixture.
  • composer stan — clean.
  • composer cs-check — clean.

OrmResolver::getEntityPolicy() and getRepositoryPolicy() already mapped the
namespace segment of the resource class from backslashes to forward
slashes before handing it to App::className(), but the trailing name
segment was left untouched. For a class like
TestApp\Model\Entity\SubDir\Widget the resolver therefore handed
App::className() the string `App.SubDir\Widget`, which short-circuits on
the embedded backslash and returns null - producing a
MissingPolicyException even when the policy exists at
App\Policy\SubDir\WidgetPolicy.

Apply the same str_replace on the name segment in both entity and
repository resolution. Cover with regression tests using new SubDir
Widget / WidgetsTable fixtures.
@dereuromark dereuromark added this to the 3.x milestone May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with sub-directories

1 participant