1 | <?php |
||
64 | class AttributesBehavior extends Behavior |
||
65 | { |
||
66 | /** |
||
67 | * @var array list of attributes that are to be automatically filled with the values specified via enclosed arrays. |
||
68 | * The array keys are the ActiveRecord attributes upon which the events are to be updated, |
||
69 | * and the array values are the array of corresponding events(s). For this enclosed array: |
||
70 | * the array keys are the ActiveRecord events upon which the attributes are to be updated, |
||
71 | * and the array values are the value that will be assigned to the current attributes. This can be an anonymous function, |
||
72 | * callable in array format (e.g. `[$this, 'methodName']`), an [[\yii\db\Expression|Expression]] object representing a DB expression |
||
73 | * (e.g. `new Expression('NOW()')`), scalar, string or an arbitrary value. If the former, the return value of the |
||
74 | * function will be assigned to the attributes. |
||
75 | * |
||
76 | * ```php |
||
77 | * [ |
||
78 | * 'attribute1' => [ |
||
79 | * ActiveRecord::EVENT_BEFORE_INSERT => new Expression('NOW()'), |
||
80 | * ActiveRecord::EVENT_BEFORE_UPDATE => \Yii::$app->formatter->asDatetime('2017-07-13'), |
||
81 | * ], |
||
82 | * 'attribute2' => [ |
||
83 | * ActiveRecord::EVENT_BEFORE_VALIDATE => [$this, 'storeAttributes'], |
||
84 | * ActiveRecord::EVENT_AFTER_VALIDATE => [$this, 'restoreAttributes'], |
||
85 | * ], |
||
86 | * 'attribute3' => [ |
||
87 | * ActiveRecord::EVENT_BEFORE_VALIDATE => $fn2 = [$this, 'getAttribute2'], |
||
88 | * ActiveRecord::EVENT_AFTER_VALIDATE => $fn2, |
||
89 | * ], |
||
90 | * 'attribute4' => [ |
||
91 | * ActiveRecord::EVENT_BEFORE_DELETE => function ($event, $attribute) { |
||
92 | * static::disabled() || $event->isValid = false; |
||
93 | * }, |
||
94 | * ], |
||
95 | * ] |
||
96 | * ``` |
||
97 | */ |
||
98 | public $attributes = []; |
||
99 | /** |
||
100 | * @var array list of order of attributes that are to be automatically filled with the event. |
||
101 | * The array keys are the ActiveRecord events upon which the attributes are to be updated, |
||
102 | * and the array values are represent the order corresponding attributes. |
||
103 | * The rest of the attributes are processed at the end. |
||
104 | * If the [[attributes]] for this attribute do not specify this event, it is ignored |
||
105 | * |
||
106 | * ```php |
||
107 | * [ |
||
108 | * ActiveRecord::EVENT_BEFORE_VALIDATE => ['attribute1', 'attribute2'], |
||
109 | * ActiveRecord::EVENT_AFTER_VALIDATE => ['attribute2', 'attribute1'], |
||
110 | * ] |
||
111 | * ``` |
||
112 | */ |
||
113 | public $order = []; |
||
114 | /** |
||
115 | * @var bool whether to skip this behavior when the `$owner` has not been modified |
||
116 | */ |
||
117 | public $skipUpdateOnClean = true; |
||
118 | /** |
||
119 | * @var bool whether to preserve non-empty attribute values. |
||
120 | */ |
||
121 | public $preserveNonEmptyValues = false; |
||
122 | |||
123 | |||
124 | /** |
||
125 | * @inheritdoc |
||
126 | */ |
||
127 | 6 | public function events() |
|
136 | |||
137 | /** |
||
138 | * Evaluates the attributes values and assigns it to the current attributes. |
||
139 | * @param Event $event |
||
140 | */ |
||
141 | 6 | public function evaluateAttributes($event) |
|
164 | |||
165 | /** |
||
166 | * Returns the value for the current attributes. |
||
167 | * This method is called by [[evaluateAttributes()]]. Its return value will be assigned |
||
168 | * to the target attribute corresponding to the triggering event. |
||
169 | * @param string $attribute target attribute name |
||
170 | * @param Event $event the event that triggers the current attribute updating. |
||
171 | * @return mixed the attribute value |
||
172 | */ |
||
173 | 5 | protected function getValue($attribute, $event) |
|
185 | } |
||
186 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.