Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
isaeken committed Jun 27, 2021
1 parent 0d1fa4e commit 59649e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
24 changes: 24 additions & 0 deletions src/PluginSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class PluginSystem
*/
private Collection $plugins;

/**
* Static plugin system.
*
* @var PluginSystem $system
*/
private static PluginSystem $system;

/**
* Find plugin in loaded plugins.
*
Expand All @@ -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.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 59649e5

Please sign in to comment.