Compare commits
5 Commits
e4404cde33
..
0.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| ffdb577f7e | |||
| 46ba495fe6 | |||
| 1e60fc5d10 | |||
| d5c41c49cc | |||
| 7450c325bf |
@@ -1,3 +1,3 @@
|
|||||||
# Template
|
# Container
|
||||||
|
|
||||||
Potter Framework Component Template
|
Potter Framework Container Implementation
|
||||||
+5
-4
@@ -1,14 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "potter/template",
|
"name": "potter/container",
|
||||||
"description": "Potter Framework Component Template",
|
"description": "Potter Framework Container Implementation",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.5"
|
"php": "^8.5",
|
||||||
|
"psr/container": "^2.0"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Potter\\": "src/Potter/"
|
"Potter\\Container\\": "src/Potter/Container/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"authors": [
|
"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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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