generated from Potter/Template
initialize
This commit is contained in:
+2
-1
@@ -3,7 +3,8 @@
|
|||||||
"description": "Potter Framework Resource Interface",
|
"description": "Potter Framework Resource Interface",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.5"
|
"php": "^8.5",
|
||||||
|
"potter/aware": "^0.0.1"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Potter\Resource;
|
||||||
|
|
||||||
|
final class Resource extends AbstractResource
|
||||||
|
{
|
||||||
|
use ResourceTrait;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user