-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Set the raw data array without any mutations for the Entity #2011
Set the raw data array without any mutations for the Entity #2011
Conversation
Signed-off-by: Andrey Pyzhikov <5071@mail.ru>
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.
Good catch. But I think it can be done simpler by calling setAttributes
/setRawArray
instead of fill
in the Entity constructor. That should eliminate all of the other checks and fills in the database layer.
system/Entity.php
Outdated
* @param array $data | ||
* @return $this | ||
*/ | ||
public function setRawArray(array $data) |
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.
Rename to setAttributes
please.
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.
What checks do you mean?
And what do you think about changing the class name from Entity to AbstractEntity?
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.
Not a fan of the name change - it's not an abstract class. Even then not sure i'd like it.
Was referring to the checks in the database layer that you've added where it checks if it's an Entity and then uses setRawArray
. If we move that to the Entity constructor I don't think any of those checks are needed since things will be set to their raw values the way the database layer currently works.
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.
Then we say goodbye to the stdClass class and the custom class.
Because stdClass has no constructor, and the custom class may not have a constructor.
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.
Nothing's changing there. It works currently. The database engine itself handles that in $this->resultID->fetch_object($className);
.
I'm not saying you should remove existing functionality - but remove the portions you added in this PR. They all look something like:
if (is_subclass_of($className, Entity::class))
{
$data = $this->fetchAssoc();
return empty($data) ? false : (new $className())->setRawArray($data);
}
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'm confused.
If I remove this code
if (is_subclass_of($className, Entity::class))
{
return empty($data = $this->fetchAssoc()) ? false : new $className($data);
}
then this PR does not make sense.
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.
Actually - I might be dense here. I was thinking that it would set through the constructor, but it doesn't. It tries to set the value directly on the object. It's late and I'm tired and distracted with other problems. Sorry - what you've done works fine. Just rename that method, please.
Signed-off-by: Andrey Pyzhikov <5071@mail.ru>
Any other reason besides setting a password? |
Description
When we create, for example, the password hashing method Entity::setPassword(), this method is also called when the value from the database is filled.
As a result, we get a hash of the hash in $entity->password
This PR sets the value of the $attribute property to the unchanged values from the database.
Checklist: