implement Potter\Aware
This commit is contained in:
+4
-2
@@ -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": [
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Potter\Aware;
|
||||
|
||||
abstract class Aware extends AbstractAware
|
||||
{
|
||||
use AwareTrait, CloneableTrait;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user