|
43 | 43 | * ActiveRecord::EVENT_AFTER_VALIDATE => $fn2,
|
44 | 44 | * ],
|
45 | 45 | * '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 | + * }, |
47 | 49 | * ],
|
48 | 50 | * ],
|
49 | 51 | * ],
|
@@ -86,7 +88,9 @@ class AttributesBehavior extends Behavior
|
86 | 88 | * ActiveRecord::EVENT_AFTER_VALIDATE => $fn2,
|
87 | 89 | * ],
|
88 | 90 | * '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 | + * }, |
90 | 94 | * ],
|
91 | 95 | * ]
|
92 | 96 | * ```
|
@@ -137,7 +141,7 @@ public function events()
|
137 | 141 | public function evaluateAttributes($event)
|
138 | 142 | {
|
139 | 143 | if ($this->skipUpdateOnClean
|
140 |
| - && $event->name == ActiveRecord::EVENT_BEFORE_UPDATE |
| 144 | + && $event->name === ActiveRecord::EVENT_BEFORE_UPDATE |
141 | 145 | && empty($this->owner->dirtyAttributes)
|
142 | 146 | ) {
|
143 | 147 | return;
|
@@ -168,12 +172,12 @@ public function evaluateAttributes($event)
|
168 | 172 | */
|
169 | 173 | protected function getValue($attribute, $event)
|
170 | 174 | {
|
171 |
| - if (!isset($this->attributes[$attribute][$event])) { |
| 175 | + if (!isset($this->attributes[$attribute][$event->name])) { |
172 | 176 | return null;
|
173 | 177 | }
|
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); |
177 | 181 | }
|
178 | 182 |
|
179 | 183 | return $value;
|
|
0 commit comments