From 8672ec72a4bf0b865fe5de98eb63fb52deacab69 Mon Sep 17 00:00:00 2001 From: Jay Potter Date: Sun, 31 May 2026 19:14:24 -0400 Subject: [PATCH] implement Potter\Aware --- composer.json | 6 ++++-- src/Potter/Aware/AbstractAware.php | 16 ++++++++++++++++ src/Potter/Aware/Aware.php | 10 ++++++++++ src/Potter/Aware/AwareInterface.php | 14 ++++++++++++++ src/Potter/Aware/AwareTrait.php | 26 ++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/Potter/Aware/AbstractAware.php create mode 100644 src/Potter/Aware/Aware.php create mode 100644 src/Potter/Aware/AwareInterface.php create mode 100644 src/Potter/Aware/AwareTrait.php diff --git a/composer.json b/composer.json index ccfcc21..50261f9 100644 --- a/composer.json +++ b/composer.json @@ -3,12 +3,14 @@ "description": "Potter Framework Aware Implementation", "type": "library", "require": { - "php": "^8.5" + "php": "^8.5", + "potter/cloneable": "^0.0.1", + "potter/container": "^0.0.1" }, "license": "MIT", "autoload": { "psr-4": { - "Potter\\Aware": "src/Potter/Aware/" + "Potter\\Aware\\": "src/Potter/Aware/" } }, "authors": [ diff --git a/src/Potter/Aware/AbstractAware.php b/src/Potter/Aware/AbstractAware.php new file mode 100644 index 0000000..90922d3 --- /dev/null +++ b/src/Potter/Aware/AbstractAware.php @@ -0,0 +1,16 @@ +clone(); + $clone->set($key, $value); + return $clone; + } + + final public function without(string $key): static + { + $clone = $this->clone(); + $clone->unset($key); + return $clone; + } + + abstract public function clone(): static; + abstract protected function set(string $key, mixed $value): mixed; + abstract protected function unset(string $key): void; +}