Add with() Method

This commit is contained in:
2025-10-25 12:05:46 -04:00
parent 4dd0e11339
commit 1a0c5bdc30
3 changed files with 9 additions and 1 deletions

View File

@@ -10,4 +10,5 @@ abstract class AbstractAware implements AwareInterface
abstract public function has(string $key): bool;
abstract protected function set(string $key, mixed $value): mixed;
abstract protected function unset(string $key): void;
abstract public function with(string $key, mixed $value): AwareInterface;
}

View File

@@ -8,4 +8,5 @@ interface AwareInterface
{
public function get(string $key): mixed;
public function has(string $key): bool;
public function with(string $key, mixed $value): self;
}

View File

@@ -10,6 +10,8 @@ trait AwareTrait
{
private array $aware = [];
abstract public function clone(): CloneableInterface;
final public function get(string $key): mixed
{
return $this->aware[$key];
@@ -30,5 +32,9 @@ trait AwareTrait
unset($this->aware[$key]);
}
abstract public function clone(): CloneableInterface;
final public function with(string $key, mixed $value): AwareInterface
{
($clone = $this->clone())->set($key, $value);
return $clone;
}
}