-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginEngine.php
More file actions
51 lines (39 loc) · 1012 Bytes
/
PluginEngine.php
File metadata and controls
51 lines (39 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Codad5\SamplePlugins;
abstract class PluginEngine {
/**
* Track whether this instance has already been run
*/
private bool $hasRun = false;
// private constructor to prevent instantiation
final protected function __construct() {
}
abstract public static function getInstance(): static;
abstract protected function run(): static;
/**
* Check if this instance has already been run
*/
final public function hasRun(): bool {
return $this->hasRun;
}
/**
* Mark this instance as having been run
*/
final protected function markAsRun(): void {
$this->hasRun = true;
}
/**
* Prevent cloning of the instance
*/
final public function __clone() {
}
// static method to run a particular instance of the plugin
final public static function runInstance(PluginEngine $instance): static {
if ($instance->hasRun()) {
return $instance; // Return without running if already run
}
$result = $instance->run();
$instance->markAsRun();
return $result;
}
}