Browse Source

Update AttributeTypecastBehavior.php

Line `Handles owner 'beforeInsert' and 'beforeUpdate' events, ensuring attribute typecasting.` required for change (hotfix php docs.)
tags/2.0.14
Hryhorii Furletov 7 years ago committed by SilverFire - Dmitry Naumenko
parent
commit
798947af29
No known key found for this signature in database
GPG Key ID: 39DD917A92B270A
  1. 23
      framework/behaviors/AttributeTypecastBehavior.php

23
framework/behaviors/AttributeTypecastBehavior.php

@ -162,6 +162,14 @@ class AttributeTypecastBehavior extends Behavior
*/
public $typecastBeforeSave = false;
/**
* @var bool whether to perform typecasting after saving owner model (insert or update).
* This option may be disabled in order to achieve better performance.
* For example, in case of [[\yii\db\ActiveRecord]] usage, typecasting after save
* will grant no benefit an thus can be disabled.
* Note that changing this option value will have no effect after this behavior has been attached to the model.
*/
public $typecastAfterSave = false;
/**
* @var bool whether to perform typecasting after retrieving owner model data from
* the database (after find or refresh).
* This option may be disabled in order to achieve better performance.
@ -307,6 +315,10 @@ class AttributeTypecastBehavior extends Behavior
$events[BaseActiveRecord::EVENT_BEFORE_INSERT] = 'beforeSave';
$events[BaseActiveRecord::EVENT_BEFORE_UPDATE] = 'beforeSave';
}
if ($this->typecastAfterSave) {
$events[BaseActiveRecord::EVENT_AFTER_INSERT] = 'afterSave';
$events[BaseActiveRecord::EVENT_AFTER_UPDATE] = 'afterSave';
}
if ($this->typecastAfterFind) {
$events[BaseActiveRecord::EVENT_AFTER_FIND] = 'afterFind';
}
@ -326,7 +338,7 @@ class AttributeTypecastBehavior extends Behavior
}
/**
* Handles owner 'afterInsert' and 'afterUpdate' events, ensuring attribute typecasting.
* Handles owner 'beforeInsert' and 'beforeUpdate' events, ensuring attribute typecasting.
* @param \yii\base\Event $event event instance.
*/
public function beforeSave($event)
@ -335,6 +347,15 @@ class AttributeTypecastBehavior extends Behavior
}
/**
* Handles owner 'afterInsert' and 'afterUpdate' events, ensuring attribute typecasting.
* @param \yii\base\Event $event event instance.
*/
public function afterSave($event)
{
$this->typecastAttributes();
}
/**
* Handles owner 'afterFind' event, ensuring attribute typecasting.
* @param \yii\base\Event $event event instance.
*/

Loading…
Cancel
Save