|
|
|
@ -7,6 +7,8 @@
|
|
|
|
|
|
|
|
|
|
namespace yii\behaviors; |
|
|
|
|
|
|
|
|
|
use Closure; |
|
|
|
|
use yii\base\Event; |
|
|
|
|
use yii\base\InvalidCallException; |
|
|
|
|
use yii\db\BaseActiveRecord; |
|
|
|
|
use yii\db\Expression; |
|
|
|
@ -78,10 +80,8 @@ class TimestampBehavior extends AttributeBehavior
|
|
|
|
|
*/ |
|
|
|
|
public $updatedAtAttribute = 'updated_at'; |
|
|
|
|
/** |
|
|
|
|
* @var callable|Expression The expression that will be used for generating the timestamp. |
|
|
|
|
* This can be either an anonymous function that returns the timestamp value, |
|
|
|
|
* or an [[Expression]] object representing a DB expression (e.g. `new Expression('NOW()')`). |
|
|
|
|
* If not set, it will use the value of `time()` to set the attributes. |
|
|
|
|
* {@inheritdoc} |
|
|
|
|
* In case, when the value is null - the [[time()]] function value will be used. |
|
|
|
|
*/ |
|
|
|
|
public $value; |
|
|
|
|
|
|
|
|
@ -102,15 +102,15 @@ class TimestampBehavior extends AttributeBehavior
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @inheritdoc |
|
|
|
|
* {@inheritdoc} |
|
|
|
|
* [[time()]] function return value will be used, when [[value]] is null. |
|
|
|
|
*/ |
|
|
|
|
protected function getValue($event) |
|
|
|
|
{ |
|
|
|
|
if ($this->value instanceof Expression) { |
|
|
|
|
return $this->value; |
|
|
|
|
} else { |
|
|
|
|
return $this->value !== null ? call_user_func($this->value, $event) : time(); |
|
|
|
|
if ($this->value === null) { |
|
|
|
|
return time(); |
|
|
|
|
} |
|
|
|
|
return parent::getValue($event); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|