From d526ae4e4d8f097839a2012264045ced36945151 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 31 Mar 2024 18:08:04 +0200 Subject: [PATCH] Add more examples --- examples/1-basic.php | 25 ++++++++- examples/2-automatic.php | 87 ++++++++++++++++++++++++++++++ src/Annotations/OrmMappedArray.php | 6 +-- 3 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 examples/2-automatic.php diff --git a/examples/1-basic.php b/examples/1-basic.php index 8bedde4..acb95d5 100644 --- a/examples/1-basic.php +++ b/examples/1-basic.php @@ -1,16 +1,39 @@ build(); + +/** + * Main class of your application. + */ +final class Application +{ + use DbAutoProperties; + + /** + * This field is automatically connected to the database using the specified Settings. + */ + #[OrmMappedArray(KeyType::STRING, ValueType::INT)] + private DbArray $dbProperty; + + public function __construct( + Settings $settings, + string $tablePrefix + ) { + $this->initDbProperties($settings, $tablePrefix); + } + + public function businessLogic(): void + { + $this->dbProperty['someKey'] = 123; + var_dump($this->dbProperty['someKey']); + } + + public function shutdown(): void + { + // Flush all database caches, saving all changes. + $this->saveDbProperties(); + } +} + + +$app = new Application($settings, 'tablePrefix'); +$app->businessLogic(); +$app->shutdown(); \ No newline at end of file diff --git a/src/Annotations/OrmMappedArray.php b/src/Annotations/OrmMappedArray.php index efd5a65..89f24b1 100644 --- a/src/Annotations/OrmMappedArray.php +++ b/src/Annotations/OrmMappedArray.php @@ -20,10 +20,10 @@ use Attribute; use danog\AsyncOrm\KeyType; use danog\AsyncOrm\ValueType; -/** +/** * Attribute use to autoconfigure ORM properties. - * - * @api + * + * @api */ #[Attribute(Attribute::TARGET_PROPERTY)] final class OrmMappedArray