Compare commits

...

4 Commits

Author SHA1 Message Date
b5850e4fc3 Extend ContainerInterface 2025-10-25 13:04:35 -04:00
6f05915e06 get() Method Throws NotFoundException 2025-10-25 13:03:01 -04:00
865f50ad9b Create NotFoundException 2025-10-25 12:48:52 -04:00
e91a72117a Require potter/throwable 2025-10-25 12:46:45 -04:00
4 changed files with 22 additions and 3 deletions

View File

@@ -3,7 +3,9 @@
"type": "library", "type": "library",
"require": { "require": {
"php": "^8.4", "php": "^8.4",
"potter/cloneable": "dev-main" "potter/cloneable": "dev-main",
"potter/throwable": "dev-main",
"psr/container": "^2.0@dev"
}, },
"license": "MIT", "license": "MIT",
"autoload": { "autoload": {

View File

@@ -5,8 +5,9 @@ declare(strict_types=1);
namespace Potter\Aware; namespace Potter\Aware;
use \Potter\Cloneable\CloneableInterface; use \Potter\Cloneable\CloneableInterface;
use \Psr\Container\ContainerInterface;
interface AwareInterface extends CloneableInterface interface AwareInterface extends CloneableInterface, ContainerInterface
{ {
public function get(string $key): mixed; public function get(string $key): mixed;
public function has(string $key): bool; public function has(string $key): bool;

View File

@@ -14,7 +14,10 @@ trait AwareTrait
final public function get(string $key): mixed final public function get(string $key): mixed
{ {
return $this->aware[$key]; if ($this->has($key)) {
return $this->aware[$key];
}
throw new NotFoundException;
} }
final public function has(string $key): bool final public function has(string $key): bool

View File

@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Potter\Aware;
use \Psr\Container\NotFoundExceptionInterface;
use \Potter\Throwable\Throwable;
final class NotFoundException extends Throwable implements NotFoundExceptionInterface
{
}