Support sub-directory entities and tables in OrmResolver#331
Open
dereuromark wants to merge 2 commits into
Open
Support sub-directory entities and tables in OrmResolver#331dereuromark wants to merge 2 commits into
dereuromark wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #315.
Background
The
OrmResolveralready converts the namespace segment of a resource class from backslashes to forward slashes before handing it toApp::className():…but the name segment is left as-is. For a class like
TestApp\Model\Entity\SubDir\Widgetthe resolver therefore passesApp.SubDir\WidgettoApp::className().App::className()short-circuits on any embedded backslash and returnsnull, so aMissingPolicyExceptionis thrown even whenApp\Policy\SubDir\WidgetPolicyexists 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 bothgetEntityPolicy()andgetRepositoryPolicy().Note on previous discussion
Issue #315 was closed as "use FQCN" — that workaround still works (via
MapResolverregistration), and consumers who want manual control can keep doing it. This PR is additive: nothing changes for flat layouts, and the same conventionApp\Policy\SubDir\WidgetPolicyforApp\Model\Entity\SubDir\Widgetsimply 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 aSubDir/Widget(s)fixture.composer stan— clean.composer cs-check— clean.