Compare commits
5 Commits
be15ce3fa3
...
85887e02ff
| Author | SHA1 | Date | |
|---|---|---|---|
| 85887e02ff | |||
| 87df263393 | |||
| 06b1ea046e | |||
| 16851ec519 | |||
| 00e605ec9e |
@@ -0,0 +1,3 @@
|
|||||||
|
composer.lock
|
||||||
|
/nbproject/
|
||||||
|
/vendor/
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "potter/resource",
|
||||||
|
"type": "library",
|
||||||
|
"require": {
|
||||||
|
"php": "^8.5"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Potter\\Resource\\": "src/Potter/Resource/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Jay Potter",
|
||||||
|
"email": "j@ypotter.ca"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"minimum-stability": "stable"
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Potter\Resource;
|
||||||
|
|
||||||
|
interface ResourceAwareInterface
|
||||||
|
{
|
||||||
|
public function detachResource();
|
||||||
|
public function getResource();
|
||||||
|
public function getResourceId(): int;
|
||||||
|
public function getResourceType(): string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Potter\Resource;
|
||||||
|
|
||||||
|
trait ResourceAwareTrait
|
||||||
|
{
|
||||||
|
private $resource;
|
||||||
|
|
||||||
|
final public function detachResource()
|
||||||
|
{
|
||||||
|
$resource = $this->resource;
|
||||||
|
$this->resource = null;
|
||||||
|
return $resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public function getResource()
|
||||||
|
{
|
||||||
|
return $this->resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
final public function getResourceId(): int
|
||||||
|
{
|
||||||
|
return get_resource_id($this->resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
final public function getResourceType(): string
|
||||||
|
{
|
||||||
|
return get_resource_type($this->resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
final protected function setResource($resource)
|
||||||
|
{
|
||||||
|
$this->resource = $resource;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user