[14.x] Adds PHP Attribute helper [WIP]#60254
Draft
DarkGhostHunter wants to merge 1 commit into
Draft
Conversation
|
Thanks for submitting a PR! Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
cc06fbd to
22452d3
Compare
22452d3 to
1dfcf89
Compare
Contributor
|
https://github.com/spatie/php-attribute-reader already does a lot of this; maybe it would make sense to see if efforts there could be leveraged there, and otherwise improve there? |
Contributor
Author
Didn't saw that. Guess I'll have to simplify this PR. |
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.
What?
This PR introduces the
Attrhelper to retrieve attributes instances from any target (Classes/Objects, Methods or Properties) in one line.There are three intentions behind this PR:
...and that was just the simplest offender.
Usages
There are three main usages that I've found across the framework:
getAttributes()return an array, additional checks must be done to check is not empty, and then instance the first attribute to retrieve the value correctly.do-whileloop to get all the attributes including ancestors.In light of that, I made the helper with the intention of simplify these tasks, and centralise the attribute retrieval.
Conveniences
This helper may look like over-engineering attribute retrieval, but in reality is just simply offering an expressive way to retrieve an Attribute instance or value, without bringing the kitchen sink. Of course, this only works on the sections of the framework that require
illuminate/support.Here are some examples.
Integration
I took the liberty to use
Attron all framework parts that requireilluminate/support(almost all of them). I left some places of the framework as-is because adding the helper would add little to an overall verbosy code block.