AsyncOrm/tests/TestObject.php

90 lines
2.3 KiB
PHP
Raw Normal View History

2024-03-28 23:07:09 +01:00
<?php declare(strict_types=1);
2024-03-31 18:28:23 +02:00
/**
* Copyright 2024 Daniil Gentili.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Daniil Gentili <daniil@daniil.it>
* @copyright 2016-2024 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/license/apache-2-0 Apache 2.0
2024-03-31 19:37:48 +02:00
* @link https://github.com/danog/AsyncOrm AsyncOrm documentation
2024-03-31 18:28:23 +02:00
*/
2024-03-31 17:13:03 +02:00
namespace danog\TestAsyncOrm;
2024-03-28 23:07:09 +01:00
2024-03-29 20:24:38 +01:00
use danog\AsyncOrm\Annotations\OrmMappedArray;
use danog\AsyncOrm\DbArray;
2024-03-31 19:38:58 +02:00
use danog\AsyncOrm\DbArrayBuilder;
2024-03-29 20:24:38 +01:00
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\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-31 20:56:18 +02:00
#[OrmMappedArray(
KeyType::INT,
2024-03-31 21:36:36 +02:00
ValueType::OBJECT,
2024-03-31 20:56:18 +02:00
cacheTtl: 0,
)]
public DbArray $arr3;
#[OrmMappedArray(
KeyType::INT,
ValueType::INT,
cacheTtl: 0,
optimizeIfWastedMb: 0
)]
public DbArray $arr4;
2024-03-28 23:07:09 +01:00
public function __sleep()
{
2024-04-06 19:46:54 +02:00
return ['savedProp', 'arr', 'arr2', 'arr3', 'arr4'];
2024-03-28 23:07:09 +01:00
}
2024-03-31 19:11:42 +02:00
protected function onLoaded(DbArrayBuilder $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++;
}
}