Add with() Method
This commit is contained in:
@@ -10,4 +10,5 @@ abstract class AbstractAware implements AwareInterface
|
|||||||
abstract public function has(string $key): bool;
|
abstract public function has(string $key): bool;
|
||||||
abstract protected function set(string $key, mixed $value): mixed;
|
abstract protected function set(string $key, mixed $value): mixed;
|
||||||
abstract protected function unset(string $key): void;
|
abstract protected function unset(string $key): void;
|
||||||
|
abstract public function with(string $key, mixed $value): AwareInterface;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ interface AwareInterface
|
|||||||
{
|
{
|
||||||
public function get(string $key): mixed;
|
public function get(string $key): mixed;
|
||||||
public function has(string $key): bool;
|
public function has(string $key): bool;
|
||||||
|
public function with(string $key, mixed $value): self;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ trait AwareTrait
|
|||||||
{
|
{
|
||||||
private array $aware = [];
|
private array $aware = [];
|
||||||
|
|
||||||
|
abstract public function clone(): CloneableInterface;
|
||||||
|
|
||||||
final public function get(string $key): mixed
|
final public function get(string $key): mixed
|
||||||
{
|
{
|
||||||
return $this->aware[$key];
|
return $this->aware[$key];
|
||||||
@@ -30,5 +32,9 @@ trait AwareTrait
|
|||||||
unset($this->aware[$key]);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user