From 0d1fa4e18f3928f21c168cd0602ba2febc547a35 Mon Sep 17 00:00:00 2001 From: Isa Eken Date: Sun, 27 Jun 2021 15:18:41 +0300 Subject: [PATCH 1/2] update readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 51be68e..bbe0acc 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,6 @@ Make and add own plugins to your script and make it flexible ## Roadmap -- Static autoloader generator like composer - - Laravel integration From 59649e519d39f8828234dec9a62c843ac22492fd Mon Sep 17 00:00:00 2001 From: Isa Eken Date: Sun, 27 Jun 2021 15:21:55 +0300 Subject: [PATCH 2/2] wip --- composer.json | 2 +- src/PluginSystem.php | 24 ++++++++++++++++++++++++ tests/GeneralTest.php | 6 ++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e263d30..5b6f013 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "isaeken/plugin-system", - "version": "1.4.6", + "version": "1.5.0", "type": "library", "description": "Plugin support and management library for your project", "keywords": ["plugin", "extension", "support", "management"], diff --git a/src/PluginSystem.php b/src/PluginSystem.php index 5f90c72..e339725 100644 --- a/src/PluginSystem.php +++ b/src/PluginSystem.php @@ -27,6 +27,13 @@ class PluginSystem */ private Collection $plugins; + /** + * Static plugin system. + * + * @var PluginSystem $system + */ + private static PluginSystem $system; + /** * Find plugin in loaded plugins. * @@ -47,6 +54,23 @@ private function findPlugin(PluginInterface|string $plugin): PluginInterface throw new PluginNotFoundException; } + /** + * @return static + */ + public function makeStatic(): static + { + static::$system = $this; + return $this; + } + + /** + * @return static + */ + public static function getInstance(): static + { + return static::$system; + } + /** * PluginSystem constructor. * diff --git a/tests/GeneralTest.php b/tests/GeneralTest.php index a16362c..6f6e7bd 100644 --- a/tests/GeneralTest.php +++ b/tests/GeneralTest.php @@ -28,6 +28,12 @@ public function testAutoloader() $this->assertCount(2, static::pluginSystem()->plugins()); } + public function testStatic() + { + static::pluginSystem()->makeStatic(); + $this->assertEquals(static::pluginSystem(), PluginSystem::getInstance()); + } + public function testDisable() { static::pluginSystem()->plugins()->each(function (PluginInterface $plugin) {