Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8672ec72a4 | |||
| 7d99358220 | |||
| c9d2aa1170 |
@@ -1,3 +1,3 @@
|
|||||||
# Template
|
# Template
|
||||||
|
|
||||||
Potter Framework Component Template
|
Potter Framework Aware Implementation
|
||||||
+6
-4
@@ -1,14 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "potter/template",
|
"name": "potter/aware",
|
||||||
"description": "Potter Framework Component Template",
|
"description": "Potter Framework Aware Implementation",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.5"
|
"php": "^8.5",
|
||||||
|
"potter/cloneable": "^0.0.1",
|
||||||
|
"potter/container": "^0.0.1"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Potter\\": "src/Potter/"
|
"Potter\\Aware\\": "src/Potter/Aware/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"authors": [
|
"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