Compare commits

...

1 Commits

Author SHA1 Message Date
jay ffdb577f7e implement ContainerInterface 2026-05-31 18:08:48 -04:00
5 changed files with 55 additions and 2 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
# Container
Potter Framework Container Interface
Potter Framework Container Implementation
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "potter/container",
"description": "Potter Framework Container Interface",
"description": "Potter Framework Container Implementation",
"type": "library",
"require": {
"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;
}
+10
View File
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Potter\Container;
abstract class Container extends AbstractContainer
{
use ContainerTrait;
}
+30
View File
@@ -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]);
}
}