implement Potter\Aware

This commit is contained in:
2026-05-31 19:14:24 -04:00
parent 7d99358220
commit 8672ec72a4
5 changed files with 70 additions and 2 deletions
+4 -2
View File
@@ -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": [
+16
View File
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Potter\Aware;
use \Potter\Cloneable\CloneableTrait;
use \Potter\Container\Container;
abstract class AbstractAware extends Container
{
use CloneableTrait;
abstract public function with(string $key, mixed $value): static;
abstract public function without(string $key): static;
}
+10
View File
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Potter\Aware;
abstract class Aware extends AbstractAware
{
use AwareTrait, CloneableTrait;
}
+14
View File
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Potter\Aware;
use \Potter\Cloneable\CloneableInterface;
use \Potter\Container\ContainerInterface;
interface AwareInterface extends CloneableInterface, ContainerInterface
{
public function with(string $key, mixed $value): static;
public function without(string $key): static;
}
+26
View File
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Potter\Aware;
trait AwareTrait
{
final public function with(string $key, mixed $value): static
{
$clone = $this->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;
}