Final Class Yiisoft\ActiveRecord\Event\Handler\DefaultDateTimeOnInsert
| Inheritance | Yiisoft\ |
|---|
Attribute for setting default value of the date and time for properties before inserting a new record into
the database. By default, it sets the current date and time to the created_at and updated_at properties.
It can be applied to classes or properties, and it can be repeated for multiple properties.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| getEventHandlers() | Yiisoft\ |
|
| getPropertyNames() | Returns the list of property names the handler should be applied to. | Yiisoft\ |
| setPropertyNames() | Sets the list of property names the handler should be applied to. | Yiisoft\ |
Method Details
| public mixed __construct ( mixed $value = null, string $propertyNames ) | ||
| $value | mixed | |
| $propertyNames | string | |
public function __construct(
mixed $value = null,
string ...$propertyNames,
) {
$value ??= static fn(): DateTimeImmutable => new DateTimeImmutable();
if (empty($propertyNames)) {
$propertyNames = ['created_at', 'updated_at'];
}
parent::__construct($value, ...$propertyNames);
}
| public array getEventHandlers ( ) |
public function getEventHandlers(): array
{
return [
BeforeInsert::class => $this->beforeInsert(...),
BeforeUpsert::class => $this->beforeUpsert(...),
];
}
Defined in:
Yiisoft\
Returns the list of property names the handler should be applied to.
| public string[] getPropertyNames ( ) |
public function getPropertyNames(): array
{
return $this->propertyNames;
}
Defined in:
Yiisoft\
Sets the list of property names the handler should be applied to.
| public void setPropertyNames ( string[] $propertyNames ) | ||
| $propertyNames | string[] | |
public function setPropertyNames(array $propertyNames): void
{
$this->propertyNames = $propertyNames;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.