From e751fae11ed07cdc922003d7498489f119ec4ad9 Mon Sep 17 00:00:00 2001 From: Isa Eken Date: Sun, 27 Jun 2021 16:03:49 +0300 Subject: [PATCH] added laravel integration --- README.md | 42 +++++++++++++++++++++++--- composer.json | 12 +++++++- config/plugins.php | 7 +++++ src/PluginSystemFacade.php | 18 +++++++++++ src/PluginSystemServiceProvider.php | 46 +++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 config/plugins.php create mode 100644 src/PluginSystemFacade.php create mode 100644 src/PluginSystemServiceProvider.php diff --git a/README.md b/README.md index bbe0acc..d560ba4 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,15 @@ Make and add own plugins to your script and make it flexible - Enable, disable or load plugins in runtime - Detailed execution info like extension function executed seconds +## Installation -## Roadmap +Install plugin-system with composer -- Laravel integration +```bash + composer require isaeken/plugin-system +``` - -## Installation +## Installation in Laravel Install plugin-system with composer @@ -30,6 +32,31 @@ Install plugin-system with composer composer require isaeken/plugin-system ``` +Publish configuration file + +```bash +php artisan vendor:publish --provider="IsaEken\PluginSystem\PluginSystemServiceProvider" +``` + +Set your configuration + +```php +// config/plugins.php + base_path('plugins'), + 'nested' => false, + 'folders' => true, +]; +``` + +(Optionally) +Add provider to ``config/app.php`` +```php +\IsaEken\PluginSystem\PluginSystemServiceProvider::class +``` + ## Example ```php @@ -40,6 +67,13 @@ if (! $pluginSystem->execute('hello_world')) { } ``` +### In Laravel + +```php +if (! app()->plugins->execute('hello_world')) { + return 'some plugins given an error.'; +} +``` ## Running Tests diff --git a/composer.json b/composer.json index 5b6f013..7a2aa0e 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "isaeken/plugin-system", - "version": "1.5.0", + "version": "1.5.3", "type": "library", "description": "Plugin support and management library for your project", "keywords": ["plugin", "extension", "support", "management"], @@ -20,6 +20,16 @@ "config": { "sort-packages": true }, + "extra": { + "laravel": { + "provider": [ + "IsaEken\\PluginSystem\\PluginSystemServiceProvider" + ], + "aliases": { + "PluginSystem": "IsaEken\\PluginSystem\\PluginSystemFacade" + } + } + }, "scripts": { "test": "vendor/bin/phpunit" }, diff --git a/config/plugins.php b/config/plugins.php new file mode 100644 index 0000000..f9e57de --- /dev/null +++ b/config/plugins.php @@ -0,0 +1,7 @@ + base_path('plugins'), + 'nested' => false, + 'folders' => true, +]; diff --git a/src/PluginSystemFacade.php b/src/PluginSystemFacade.php new file mode 100644 index 0000000..d56e6d1 --- /dev/null +++ b/src/PluginSystemFacade.php @@ -0,0 +1,18 @@ +app->bind('plugins', function ($app) { + if (! is_dir(config('plugins.directory'))) { + mkdir(config('plugins.directory')); + } + + return (new PluginSystem(config('plugins.directory')))->autoload( + null, + config('plugins.nested'), + config('plugins.folders'), + ); + }); + + if ($this->app->runningInConsole()) { + $this->publishes([ + __DIR__ . '/../config/plugins.php' => config_path('plugins.php'), + ], 'config'); + } + } + + /** + * Register the application services. + * + * @return void + */ + public function register() + { + $this->mergeConfigFrom(__DIR__ . '/../config/plugins.php', 'plugins'); + } +}