Skip to content

Commit

Permalink
Merge pull request #2 from isaeken/1.5
Browse files Browse the repository at this point in the history
1.5
  • Loading branch information
isaeken authored Jun 27, 2021
2 parents fa467da + 59649e5 commit 99b3609
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Make and add own plugins to your script and make it flexible

## Roadmap

- Static autoloader generator like composer

- Laravel integration


Expand Down
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 99b3609

Please sign in to comment.