Skip to content

Commit 6ffa5fb

Browse files
committed
Additional fixes for yiisoft#14151
1 parent 2b9b0c7 commit 6ffa5fb

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

framework/behaviors/AttributesBehavior.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
* ActiveRecord::EVENT_AFTER_VALIDATE => $fn2,
4444
* ],
4545
* 'attribute4' => [
46-
* ActiveRecord::EVENT_BEFORE_DELETE => function($event) {static::disabled() || $event->isValid = false;},
46+
* ActiveRecord::EVENT_BEFORE_DELETE => function ($event) {
47+
* static::disabled() || $event->isValid = false;
48+
* },
4749
* ],
4850
* ],
4951
* ],
@@ -86,7 +88,9 @@ class AttributesBehavior extends Behavior
8688
* ActiveRecord::EVENT_AFTER_VALIDATE => $fn2,
8789
* ],
8890
* 'attribute4' => [
89-
* ActiveRecord::EVENT_BEFORE_DELETE => function($event) {static::disabled() || $event->isValid = false;},
91+
* ActiveRecord::EVENT_BEFORE_DELETE => function ($event) {
92+
* static::disabled() || $event->isValid = false;
93+
* },
9094
* ],
9195
* ]
9296
* ```
@@ -137,7 +141,7 @@ public function events()
137141
public function evaluateAttributes($event)
138142
{
139143
if ($this->skipUpdateOnClean
140-
&& $event->name == ActiveRecord::EVENT_BEFORE_UPDATE
144+
&& $event->name === ActiveRecord::EVENT_BEFORE_UPDATE
141145
&& empty($this->owner->dirtyAttributes)
142146
) {
143147
return;
@@ -168,12 +172,12 @@ public function evaluateAttributes($event)
168172
*/
169173
protected function getValue($attribute, $event)
170174
{
171-
if (!isset($this->attributes[$attribute][$event])) {
175+
if (!isset($this->attributes[$attribute][$event->name])) {
172176
return null;
173177
}
174-
$value = $this->attributes[$attribute][$event];
175-
if ($value instanceof Closure || is_array($value) && is_callable($value)) {
176-
return call_user_func($value, $attribute, $event);
178+
$value = $this->attributes[$attribute][$event->name];
179+
if ($value instanceof Closure || (is_array($value) && is_callable($value))) {
180+
return $value($event);
177181
}
178182

179183
return $value;

0 commit comments

Comments
 (0)