Skip to content
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

feat: add Entity::injectRawData() to avoid name collision #7208

Merged
merged 2 commits into from
Feb 13, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Feb 1, 2023

Description
Supersedes #5763, #5781
Fixes #5762

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added enhancement PRs that improve existing functionalities 4.4 labels Feb 1, 2023
@kenjis kenjis force-pushed the feat-add-entity-injectRawData branch from adc2f12 to 7902b18 Compare February 1, 2023 06:08
@iRedds
Copy link
Collaborator

iRedds commented Feb 1, 2023

To be honest, I do not agree with this PR.
I believe that the implementation should be elegant like in laravel.
And adding reflection is already too much.
In my opinion, setters and getters should not be public, as they are specially made for the hidden implementation of logic.

@kenjis
Copy link
Member Author

kenjis commented Feb 1, 2023

Thank you for your comment.

I believe that the implementation should be elegant like in laravel.

Can you elaborate? elegant like in laravel explains nothing to me.

@iRedds
Copy link
Collaborator

iRedds commented Feb 1, 2023

To serve an entity
setAttributes()
getAttributes() instead of toRawArray()

setter and getter for attributes
setAttributeNameAttribute()
getAttributeNameAttribute()

Otherwise, any new entity functionality (method names) will need to be adjusted for the fact that the developer may have an attribute with the same name.

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the public requirement being necessary here, and it is a very likely breaking change. We can discuss it here, or my preference would be to split it out into a separate PR and proceed with the injection method.

@kenjis kenjis force-pushed the feat-add-entity-injectRawData branch from 7902b18 to 31a2e83 Compare February 7, 2023 08:39
@kenjis
Copy link
Member Author

kenjis commented Feb 7, 2023

I don't see the public requirement being necessary here, and it is a very likely breaking change.

Indeed.

I dropped it.

@kenjis
Copy link
Member Author

kenjis commented Feb 7, 2023

@iRedds
I don't think we need getAttributes(). The attributes property (or the word attributes) should not be actively disclosed. It is just an internal implementation.

@kenjis kenjis requested a review from MGatner February 7, 2023 09:53
@iRedds
Copy link
Collaborator

iRedds commented Feb 7, 2023

@kenjis The getAttributes() method is the normal name for a class property getter. Just like setAttributes().

Sorry, but I don't agree with you.
The developer can create his own implementation of the model that works with the entity, which means that he must be able to receive data from the entity as is.
It is not clear to me what kind of internal implementation we are talking about.

@kenjis
Copy link
Member Author

kenjis commented Feb 7, 2023

In my opinion, the attributes property is not a normal property.
It should be hidden from users.

In fact, the attributes holds all the data for the record, but that is just the current implementation.
There could be another implementation, and it does not matter if the name attributes is changed.
It is an internal implementation and should be hidden.
Users do not need to be aware of it, and if they cannot use it without being aware of it,
then it is poorly implemented.

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Re: getAttributes()... how is this different than toRawArray()?

@kenjis kenjis added the docs needed Pull requests needing documentation write-ups and/or revisions. label Feb 11, 2023
@kenjis kenjis force-pushed the feat-add-entity-injectRawData branch from 31a2e83 to 63a00bb Compare February 11, 2023 01:53
@kenjis kenjis removed the docs needed Pull requests needing documentation write-ups and/or revisions. label Feb 11, 2023
@kenjis
Copy link
Member Author

kenjis commented Feb 11, 2023

Added changelog.

@kenjis
Copy link
Member Author

kenjis commented Feb 11, 2023

I think this PR is ready to merge.

@mostafakhudair @najdanovicivan Any comments?

@kenjis kenjis merged commit 2114443 into codeigniter4:4.4 Feb 13, 2023
@kenjis kenjis deleted the feat-add-entity-injectRawData branch February 13, 2023 23:43
@kenjis
Copy link
Member Author

kenjis commented Feb 13, 2023

Thank you for the review! @MGatner @najdanovicivan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.4 enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants