Compare commits

..

5 Commits

Author SHA1 Message Date
jay ffdb577f7e implement ContainerInterface 2026-05-31 18:08:48 -04:00
jay 46ba495fe6 create ContainerInterface 2026-05-31 17:56:36 -04:00
jay 1e60fc5d10 require psr/container 2026-05-31 17:54:44 -04:00
jay d5c41c49cc fix description 2026-05-31 17:53:08 -04:00
jay 7450c325bf refractor to potter/container 2026-05-31 17:52:31 -04:00
6 changed files with 73 additions and 6 deletions
+2 -2
View File
@@ -1,3 +1,3 @@
# Template
# Container
Potter Framework Component Template
Potter Framework Container Implementation
+5 -4
View File
@@ -1,14 +1,15 @@
{
"name": "potter/template",
"description": "Potter Framework Component Template",
"name": "potter/container",
"description": "Potter Framework Container Implementation",
"type": "library",
"require": {
"php": "^8.5"
"php": "^8.5",
"psr/container": "^2.0"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Potter\\": "src/Potter/"
"Potter\\Container\\": "src/Potter/Container/"
}
},
"authors": [
@@ -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;
}
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Potter\Container;
use \Psr\Container\ContainerInterface as BaseContainerInterface;
interface ContainerInterface extends BaseContainerInterface
{
public function get(string $key): mixed;
public function has(string $key): bool;
}
+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]);
}
}