AsyncOrm/tests/TestObject.php

54 lines
1.1 KiB
PHP
Raw Normal View History

2024-03-28 23:07:09 +01:00
<?php declare(strict_types=1);
namespace danog\AsyncOrm\Test;
2024-03-29 20:24:38 +01:00
use danog\AsyncOrm\Annotations\OrmMappedArray;
use danog\AsyncOrm\DbArray;
use danog\AsyncOrm\DbAutoProperties;
2024-03-28 23:07:09 +01:00
use danog\AsyncOrm\DbObject;
2024-03-29 20:24:38 +01:00
use danog\AsyncOrm\FieldConfig;
use danog\AsyncOrm\KeyType;
use danog\AsyncOrm\ValueType;
2024-03-28 23:07:09 +01:00
final class TestObject extends DbObject
{
2024-03-29 20:24:38 +01:00
use DbAutoProperties;
2024-03-28 23:07:09 +01:00
public int $loadedCnt = 0;
public int $saveAfterCnt = 0;
public int $saveBeforeCnt = 0;
public mixed $savedProp = null;
2024-03-29 20:24:38 +01:00
#[OrmMappedArray(
KeyType::INT,
ValueType::INT
)]
public DbArray $arr;
2024-03-29 20:39:44 +01:00
#[OrmMappedArray(
KeyType::INT,
ValueType::INT
)]
public DbArray $arr2;
2024-03-29 20:24:38 +01:00
2024-03-28 23:07:09 +01:00
public function __sleep()
{
2024-03-29 20:24:38 +01:00
return ['savedProp', 'arr'];
2024-03-28 23:07:09 +01:00
}
2024-03-29 20:24:38 +01:00
protected function onLoaded(FieldConfig $config): void
2024-03-28 23:07:09 +01:00
{
2024-03-29 20:24:38 +01:00
$this->initDbProperties($config->settings, $config->table);
2024-03-28 23:07:09 +01:00
$this->loadedCnt++;
}
protected function onAfterSave(): void
{
$this->saveAfterCnt++;
}
protected function onBeforeSave(): void
{
2024-03-29 20:24:38 +01:00
$this->saveDbProperties();
2024-03-28 23:07:09 +01:00
$this->saveBeforeCnt++;
}
}