Compare commits
1 Commits
46ba495fe6
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ffdb577f7e |
@@ -1,3 +1,3 @@
|
|||||||
# Container
|
# Container
|
||||||
|
|
||||||
Potter Framework Container Interface
|
Potter Framework Container Implementation
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "potter/container",
|
"name": "potter/container",
|
||||||
"description": "Potter Framework Container Interface",
|
"description": "Potter Framework Container Implementation",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.5",
|
"php": "^8.5",
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Potter\Container;
|
||||||
|
|
||||||
|
abstract class AbstractContainer implements ContainerInterface
|
||||||
|
{
|
||||||
|
abstract public function get(string $key): mixed;
|
||||||
|
abstract public function has(string $key): bool;
|
||||||
|
abstract protected function set(string $key, mixed $value): mixed;
|
||||||
|
abstract protected function unset(string $key): void;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Potter\Container;
|
||||||
|
|
||||||
|
abstract class Container extends AbstractContainer
|
||||||
|
{
|
||||||
|
use ContainerTrait;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Potter\Container;
|
||||||
|
|
||||||
|
trait ContainerTrait
|
||||||
|
{
|
||||||
|
private array $container = [];
|
||||||
|
|
||||||
|
final public function get(string $key): mixed
|
||||||
|
{
|
||||||
|
return $this->container[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
final public function has(string $key): bool
|
||||||
|
{
|
||||||
|
return array_key_exists($key, $this->container);
|
||||||
|
}
|
||||||
|
|
||||||
|
final protected function set(string $key, mixed $value): mixed
|
||||||
|
{
|
||||||
|
return $this->container[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
final protected function unset(string $key): void
|
||||||
|
{
|
||||||
|
unset($this->container[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user