feat: capability can apply to entire permission class#36
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the Capability attribute so that it can be applied at the permission class level (not just constants), and updates discovery logic and fixtures accordingly. It also refines the default stubs for generating permission and capability classes to better align with the colon-delimited permission naming and common capability naming patterns.
Changes:
- Allow
#[Capability]to be applied to classes, and haveDefinitionDiscoverermerge class-level and constant-level capabilities when buildingPermissionDefinitions. - Add fixtures and unit tests to validate class-level capabilities and capability merging behavior.
- Update permission and capability stubs to use colon-delimited permission names, introduce a
VIEW_ANYpermission, and adjust default capability naming/labels.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
tests/Unit/CodeFirst/DefinitionDiscovererTest.php |
Adds tests ensuring capabilities are inherited from class-level attributes and correctly merged with constant-level capabilities. |
tests/Fixtures/CodeFirst/UserPermissions.php |
New fixture permission class with class-level and constant-level Capability attributes used to validate the new discovery behavior. |
stubs/permission.stub |
Updates the generated permission class stub to add VIEW_ANY, switch permission names to resource:action format, and refine descriptions. |
stubs/capability.stub |
Adjusts the capability stub’s label text and default capability constant name pattern. |
src/CodeFirst/DefinitionDiscoverer.php |
Extends permission discovery to read class-level Capability attributes and merge them with constant-level ones via a new helper method. |
src/Attributes/Capability.php |
Expands the Capability attribute target to include classes and documents class-level usage and multi-capability examples. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Extends the Capability attribute so that it can be applied at the permission class level (not just constants), and updates discovery logic and fixtures accordingly. It also refines the default stubs for generating permission and capability classes to better align with the colon-delimited permission naming and common capability naming patterns.