. * * @author Daniil Gentili * @author Alexander Pankratov * @copyright 2016-2024 Daniil Gentili * @copyright 2016-2024 Alexander Pankratov * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 * @link https://daniil.it/AsyncOrm AsyncOrm documentation */ namespace danog\AsyncOrm; use danog\AsyncOrm\Annotations\OrmMappedArray; use danog\AsyncOrm\Internal\Containers\ObjectContainer; use danog\AsyncOrm\Internal\Driver\CachedArray; use danog\AsyncOrm\Internal\Driver\ObjectArray; use danog\AsyncOrm\Settings\DriverSettings; use danog\AsyncOrm\Settings\Mysql; use ReflectionClass; use function Amp\async; use function Amp\Future\await; /** @api */ abstract class DbObject { private ObjectContainer $mapper; private string|int $key; /** * Initialize database instance. * * @internal */ final public function initDb(ObjectContainer $mapper, string|int $key, FieldConfig $config): void { $this->mapper = $mapper; $this->key = $key; } /** * Save object to database. */ public function save(): void { $this->onBeforeSave(); $this->mapper->inner->set($this->key, $this); $this->onAfterSave(); } /** * Method invoked before saving the object. */ protected function onBeforeSave(): void { } /** * Method invoked after saving the object. */ protected function onAfterSave(): void { } }