-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
WIP: behaviors refactoring #2360
WIP: behaviors refactoring #2360
Conversation
$model = $this->owner; | ||
$attributes = $this->attributes[$event->name]; | ||
|
||
if ($attributes !== null) { |
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.
Why is this check needed? Probably use the following code:
if (!empty($this->attributes[$event->name])) {
foreach ($this->attributes[$event->name] as $key => $val) { ...
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.
Right...I just have the habit of give that kind of properties a shorter name...
Will wait for more comments from you to refactor...
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.
The check above also ensures attributes
has the key $event->name
, even though we are almost certain.
Ok, I'm done with the code review. Thanks! |
/** | ||
* AttributeStampBehavior is used to fill an ActiveRecord's object attributes with arbitrary data when specified events occurs. | ||
* | ||
* AttributeStampBehavior is mainly used as a base class for other behaviors, like `TimestampBehavior` and `BlameableBehavior`. |
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.
AttributeStampBehavior is mainly → It is mainly
Well...after review I don't think if this could be helpful. Let me know if I can help in anything... 😃 |
Do you mean the three layer thing? |
I mean the entire refactor... |
Sorry if my code review made you feel frustrated. I think the refactoring still makes sense. I will come back to this later when I get time. |
@qiangxue never ever, I am not that kind of developer!!! 😃 |
@lucianobaraglia your code isn't bad. We just suggest how to make it better. |
Agree with @samdark. BTW, personally I don't quite like the three layers thing because it's a bit over designed and may confuse users without very good explanation and understanding. |
@samdark I know...thanks! |
ok, so if we have this behavior, should not we have then behavior for |
@Ragazzo with this approach several automatic attributes stamp could be implemented easily extending |
yes, but if so, then maybe they should go to |
i am fine with their suggestions, however some general behaviors are good, and soft-delete is one of them. the question is that should that be |
I don't think we need to put them in an extension. We usually create an extension if it has some external dependencies. Otherwise, separating them in an extension only brings trouble to users. The benefit of reducing code size is negligible. |
ok, so what is for soft-delete behavior? it is needed same time as other for updating time and blameable behavior. |
Yes, it's good to have. |
ok, @lucianobaraglia can you add behavior for soft-delete? thanks) |
@Ragazzo this PR was just a refactoring proposal that's still far to be implemented beacuse code has to be improved, I think...
Some other...? |
first two are not the same? and for what is |
What about |
|
@qiangxue it would be amazing, but I think maybe it's out of the scope of this refactoring idea... |
|
* 'master' of github.com:yiisoft/yii2: Fixes #2360: Added `AttributeBehavior` and `BlameableBehavior`, and renamed `AutoTimestamp` to `TimestampBehavior`
See #2269 and https://gist.github.com/lucianobaraglia/8d184cd9b9c7505a0b24
Usage example: