initialize

This commit is contained in:
2026-06-12 15:23:36 -04:00
parent 82b7fc6a6f
commit f4cb86e388
5 changed files with 91 additions and 1 deletions
+2 -1
View File
@@ -3,7 +3,8 @@
"description": "Potter Framework Resource Interface",
"type": "library",
"require": {
"php": "^8.5"
"php": "^8.5",
"potter/aware": "^0.0.1"
},
"license": "MIT",
"autoload": {
+17
View File
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Potter\Resource;
use \Potter\Aware\Aware;
abstract class AbstractResource extends Aware
{
abstract public function getResource();
abstract public function hasResource(): bool;
abstract protected function setResource($resource);
abstract protected function unsetResource(): void;
abstract public function withResource($resource): static;
abstract public function withoutResource(): static;
}
+10
View File
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Potter\Resource;
final class Resource extends AbstractResource
{
use ResourceTrait;
}
+15
View File
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Potter\Resource;
use \Potter\Aware\AwareInterface;
interface ResourceInterface extends AwareInterface
{
public function getResource();
public function hasResource(): bool;
public function withResource($resource): static;
public function withoutResource(): static;
}
+47
View File
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Potter\Resource;
trait ResourceTrait
{
private const string RESOURCE = 'resource';
final public function getResource()
{
return $this->get(self::RESOURCE);
}
final public function hasResource(): bool
{
return $this->has(self::RESOURCE);
}
final protected function setResource($resource)
{
return $this->set(self::RESOURCE, $resource);
}
final protected function unsetResource(): void
{
$this->unset(self::RESOURCE);
}
final public function withResource($resource): static
{
return $this->with(self::RESOURCE, $resource);
}
final public function withoutResource(): static
{
return $this->without(self::RESOURCE);
}
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;
abstract public function with(string $key, mixed $value): static;
abstract public function without(string $key): static;
}