-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch attributes from parent classes to allow reusability #581
Fetch attributes from parent classes to allow reusability #581
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, some small changes required
src/Support/DataClass.php
Outdated
->map(fn (ReflectionAttribute $reflectionAttribute) => $reflectionAttribute->newInstance()); | ||
|
||
$parent = $class->getParentClass(); | ||
if ($parent !== false && $class->getName() !== Data::class) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to check on the BaseData interface here, since in v4 we'll have mutliple base Data classes like Dto and Resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided not to exclude base class provided by the package here. Easier way, not sure if we can exclude base class based on an interface it implements as the child class will also implements this interface...
@rubenvanassche This should be better |
Looking great! Thanks! |
Thank you ! |
This PR changes class attributes resolution fetching parent classes attributes as well as current class attributes.
This allows the developer to factorize attributes declarations parent classes.
For example if we want every data to be mapped with
SnakeCaseMapper
, we currently need to declare#[MapName(SnakeCaseMapper::class)]
on every singleData
class.With this PR, we can declare a
BaseData
with the mapper and every child class with inherit with the mapper.In case the attribute is redeclared in child class, the child attribute has higher priority (parents attributes are push at the end of the collection).