From a0124b45f9dab8a0f7d4879d4ea147b414b25bf2 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 20 Sep 2015 13:11:41 -0400 Subject: [PATCH] Add sub namespace for plugins --- app/Core/{PluginBase.php => Plugin/Base.php} | 6 +++--- app/Core/{PluginLoader.php => Plugin/Loader.php} | 13 +++++++------ app/common.php | 2 +- doc/plugins.markdown | 8 ++++---- .../{PluginLoaderTest.php => Plugin/LoaderTest.php} | 8 ++++---- 5 files changed, 19 insertions(+), 18 deletions(-) rename app/Core/{PluginBase.php => Plugin/Base.php} (90%) rename app/Core/{PluginLoader.php => Plugin/Loader.php} (90%) rename tests/units/Core/{PluginLoaderTest.php => Plugin/LoaderTest.php} (78%) diff --git a/app/Core/PluginBase.php b/app/Core/Plugin/Base.php similarity index 90% rename from app/Core/PluginBase.php rename to app/Core/Plugin/Base.php index 457afa03e..580d41ad4 100644 --- a/app/Core/PluginBase.php +++ b/app/Core/Plugin/Base.php @@ -1,14 +1,14 @@ isDot() && $fileinfo->isDir()) { @@ -63,7 +64,7 @@ class PluginLoader extends Base */ public function loadSchema($plugin) { - $filename = __DIR__.'/../../plugins/'.$plugin.'/Schema/'.ucfirst(DB_DRIVER).'.php'; + $filename = __DIR__.'/../../../plugins/'.$plugin.'/Schema/'.ucfirst(DB_DRIVER).'.php'; if (file_exists($filename)) { require($filename); diff --git a/app/common.php b/app/common.php index ea38ab364..dcd571bcc 100644 --- a/app/common.php +++ b/app/common.php @@ -33,5 +33,5 @@ if (ENABLE_URL_REWRITE) { require __DIR__.'/routes.php'; } -$plugin = new Core\PluginLoader($container); +$plugin = new Core\Plugin\Loader($container); $plugin->scan(); diff --git a/doc/plugins.markdown b/doc/plugins.markdown index 7f32cf0ae..4388f7c6f 100644 --- a/doc/plugins.markdown +++ b/doc/plugins.markdown @@ -47,9 +47,9 @@ Example of `Plugin.php` file (`plugins/Foobar/Plugin.php`): namespace Plugin\Foobar; -use Core\PluginBase; +use Core\Plugin\Base; -class Plugin extends PluginBase +class Plugin extends Plugin\Base { public function initialize() { @@ -58,14 +58,14 @@ class Plugin extends PluginBase } ``` -This file should contains a class `Plugin` defined under the namespace `Plugin\Yourplugin` and extends `Core\PluginBase`. +This file should contains a class `Plugin` defined under the namespace `Plugin\Yourplugin` and extends `Core\Plugin\Base`. The only required method is `initialize()`. This method is called for each request when the plugin is loaded. Plugin methods -------------- -Available methods from `PluginBase`: +Available methods from `Plugin\Base`: - `initialize()`: Executed when the plugin is loaded - `getClasses()`: Return all classes that should be stored in the dependency injection container diff --git a/tests/units/Core/PluginLoaderTest.php b/tests/units/Core/Plugin/LoaderTest.php similarity index 78% rename from tests/units/Core/PluginLoaderTest.php rename to tests/units/Core/Plugin/LoaderTest.php index 62327f015..40c23fbba 100644 --- a/tests/units/Core/PluginLoaderTest.php +++ b/tests/units/Core/Plugin/LoaderTest.php @@ -1,14 +1,14 @@ container); + $p = new Loader($this->container); $this->assertEquals(0, $p->getSchemaVersion('not_found')); $this->assertTrue($p->setSchemaVersion('plugin1', 1));