generated from Potter/Template
add beforeClone and afterClone
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "potter/cloneable",
|
"name": "potter/cloneable",
|
||||||
"description": "Potter Framework Cloneable Interface",
|
"description": "Potter Framework Cloneable Interface",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"homepage": "https://gitpotter.com/Potter/Cloneable",
|
"homepage": "https://gitpotter.com/Potter/Cloneable",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
},
|
},
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.3"
|
"php": "^8.3",
|
||||||
|
"potter/event": "^1.0",
|
||||||
|
"league/event": "^3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Potter\Cloneable;
|
namespace Potter\Cloneable;
|
||||||
|
|
||||||
interface CloneableInterface
|
use \Potter\Event\DispatcherAwareInterface;
|
||||||
|
|
||||||
|
interface CloneableInterface extends DispatcherAwareInterface
|
||||||
{
|
{
|
||||||
public function clone(): static;
|
public function clone(): static;
|
||||||
public function __clone(): void;
|
public function __clone(): void;
|
||||||
|
|||||||
@@ -4,13 +4,30 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Potter\Cloneable;
|
namespace Potter\Cloneable;
|
||||||
|
|
||||||
|
use \League\Event\EventDispatcher as BaseDispatcher;
|
||||||
|
|
||||||
trait CloneableTrait
|
trait CloneableTrait
|
||||||
{
|
{
|
||||||
|
private const string BEFORE_CLONE = 'beforeClone';
|
||||||
|
private const string AFTER_CLONE = 'afterClone';
|
||||||
|
|
||||||
final public function clone(): static
|
final public function clone(): static
|
||||||
{
|
{
|
||||||
|
if ($this->hasEventDispatcher()) {
|
||||||
|
$this->eventDispatcher()->dispatch(self::BEFORE_CLONE);
|
||||||
|
}
|
||||||
return clone $this;
|
return clone $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __clone(): void
|
public function __clone(): void
|
||||||
{ }
|
{
|
||||||
|
if (!$this->hasEventDispatcher()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->eventDispatcher()->dispatch(self::AFTER_CLONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function eventDispatcher(): BaseDispatcher;
|
||||||
|
abstract public function hasEventDispatcher(): bool;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user