Skip to content

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

Merged
kenjis merged 2 commits into
codeigniter4:4.4from
kenjis:feat-add-entity-injectRawData
Feb 13, 2023
Merged

kenjis merged 2 commits into
codeigniter4:4.4from
kenjis:feat-add-entity-injectRawData

Conversation

@kenjis

@kenjis kenjis commented Feb 1, 2023

Copy link
Copy Markdown
Member

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

iRedds commented Feb 1, 2023

Copy link
Copy Markdown
Collaborator

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

kenjis commented Feb 1, 2023

Copy link
Copy Markdown
Member Author

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

iRedds commented Feb 1, 2023

Copy link
Copy Markdown
Collaborator

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.

@MGatner MGatner left a comment

Copy link
Copy Markdown
Member

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

kenjis commented Feb 7, 2023

Copy link
Copy Markdown
Member Author

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

Indeed.

I dropped it.

@kenjis

kenjis commented Feb 7, 2023

Copy link
Copy Markdown
Member Author

@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

iRedds commented Feb 7, 2023

Copy link
Copy Markdown
Collaborator

@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

kenjis commented Feb 7, 2023

Copy link
Copy Markdown
Member Author

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.

@MGatner MGatner left a comment

Copy link
Copy Markdown
Member

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

kenjis commented Feb 11, 2023

Copy link
Copy Markdown
Member Author

Added changelog.

@kenjis

kenjis commented Feb 11, 2023

Copy link
Copy Markdown
Member Author

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

kenjis commented Feb 13, 2023

Copy link
Copy Markdown
Member Author

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

enhancement PRs that improve existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants