generated from Potter/Template
initialize
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
||||
composer.lock
|
||||
composer.phar
|
||||
/nbproject/private/
|
||||
/nbproject/
|
||||
/vendor/
|
||||
@@ -1,3 +1,3 @@
|
||||
# Potter Framework PSR-11 Container Implementation
|
||||
# Potter Framework Container Interface
|
||||
|
||||
Hello World
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "potter/container",
|
||||
"description": "Potter Framework PSR-11 Container Implementation",
|
||||
"description": "Potter Framework Container Interface",
|
||||
"version": "1.0.0",
|
||||
"type": "library",
|
||||
"homepage": "https://gitpotter.com/Potter/Container",
|
||||
@@ -19,6 +19,7 @@
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"require": {
|
||||
"php": "^8.3"
|
||||
"php": "^8.3",
|
||||
"psr/container": "^2.0"
|
||||
}
|
||||
}
|
||||
|
||||
13
src/Potter/Container/ContainerInterface.php
Normal file
13
src/Potter/Container/ContainerInterface.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Potter\Container;
|
||||
|
||||
use \Psr\Container\ContainerInterface as PsrContainerInterface;
|
||||
|
||||
interface ContainerInterface extends PsrContainerInterface
|
||||
{
|
||||
public function get(string $key): mixed;
|
||||
public function has(string $key): bool;
|
||||
}
|
||||
25
src/Potter/Container/ContainerTrait.php
Normal file
25
src/Potter/Container/ContainerTrait.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Potter\Container;
|
||||
|
||||
trait ContainerTrait
|
||||
{
|
||||
private array $storage = [];
|
||||
|
||||
final public function get(string $key): mixed
|
||||
{
|
||||
return $this->storage[$key];
|
||||
}
|
||||
|
||||
final public function has(string $key): bool
|
||||
{
|
||||
return array_key_exists($key, $this->storage) && !is_null($this->storage[$key]);
|
||||
}
|
||||
|
||||
final protected function set(string $key, mixed $value): mixed
|
||||
{
|
||||
return $this->storage[$key] = $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user