From 1ff5c35de5dbd70a782875a91dd2232fd01b002b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:38:04 +0200 Subject: Adding upstream version 0.10.1. Signed-off-by: Daniel Baumann --- vendor/ipl/orm/src/Contract/PersistBehavior.php | 18 ++++ vendor/ipl/orm/src/Contract/PropertyBehavior.php | 104 +++++++++++++++++++++ vendor/ipl/orm/src/Contract/QueryAwareBehavior.php | 18 ++++ vendor/ipl/orm/src/Contract/RetrieveBehavior.php | 18 ++++ .../ipl/orm/src/Contract/RewriteColumnBehavior.php | 39 ++++++++ .../ipl/orm/src/Contract/RewriteFilterBehavior.php | 25 +++++ .../ipl/orm/src/Contract/RewritePathBehavior.php | 20 ++++ 7 files changed, 242 insertions(+) create mode 100644 vendor/ipl/orm/src/Contract/PersistBehavior.php create mode 100644 vendor/ipl/orm/src/Contract/PropertyBehavior.php create mode 100644 vendor/ipl/orm/src/Contract/QueryAwareBehavior.php create mode 100644 vendor/ipl/orm/src/Contract/RetrieveBehavior.php create mode 100644 vendor/ipl/orm/src/Contract/RewriteColumnBehavior.php create mode 100644 vendor/ipl/orm/src/Contract/RewriteFilterBehavior.php create mode 100644 vendor/ipl/orm/src/Contract/RewritePathBehavior.php (limited to 'vendor/ipl/orm/src/Contract') diff --git a/vendor/ipl/orm/src/Contract/PersistBehavior.php b/vendor/ipl/orm/src/Contract/PersistBehavior.php new file mode 100644 index 0000000..a6db05d --- /dev/null +++ b/vendor/ipl/orm/src/Contract/PersistBehavior.php @@ -0,0 +1,18 @@ +properties = array_flip($properties); + } else { + $this->properties = $properties; + } + } + + public function retrieve(Model $model) + { + foreach ($this->properties as $key => $ctx) { + try { + $model[$key] = $this->fromDb($model[$key], $key, $ctx); + } catch (OutOfBoundsException $_) { + // pass + } + } + } + + public function persist(Model $model) + { + foreach ($this->properties as $key => $ctx) { + try { + $model[$key] = $this->toDb($model[$key], $key, $ctx); + } catch (OutOfBoundsException $_) { + // pass + } + } + } + + /** + * Transform the given value, just fetched from the database + * + * @param mixed $value + * @param string $key + * + * @return mixed + */ + public function retrieveProperty($value, $key) + { + if (! isset($this->properties[$key])) { + return $value; + } + + return $this->fromDb($value, $key, $this->properties[$key]); + } + + /** + * Transform the given value, about to be persisted to the database + * + * @param mixed $value + * @param string $key + * + * @return mixed + */ + public function persistProperty($value, $key) + { + if (! isset($this->properties[$key])) { + return $value; + } + + return $this->toDb($value, $key, $this->properties[$key]); + } + + /** + * Transform the given value which has just been fetched from the database + * + * @param mixed $value + * @param string $key + * @param mixed $context + * + * @return mixed + */ + abstract public function fromDb($value, $key, $context); + + /** + * Transform the given value which is about to be persisted to the database + * + * @param mixed $value + * @param string $key + * @param mixed $context + * + * @return mixed + */ + abstract public function toDb($value, $key, $context); +} diff --git a/vendor/ipl/orm/src/Contract/QueryAwareBehavior.php b/vendor/ipl/orm/src/Contract/QueryAwareBehavior.php new file mode 100644 index 0000000..b67bf51 --- /dev/null +++ b/vendor/ipl/orm/src/Contract/QueryAwareBehavior.php @@ -0,0 +1,18 @@ +