Add sub namespace for plugins
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Core;
|
namespace Core\Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin Base class
|
* Plugin Base class
|
||||||
*
|
*
|
||||||
* @package core
|
* @package plugin
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
abstract class PluginBase extends Base
|
abstract class Base extends \Core\Base
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Method called for each request
|
* Method called for each request
|
||||||
@@ -1,17 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Core;
|
namespace Core\Plugin;
|
||||||
|
|
||||||
use DirectoryIterator;
|
use DirectoryIterator;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
use Core\Tool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin Loader
|
* Plugin Loader
|
||||||
*
|
*
|
||||||
* @package core
|
* @package plugin
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
*/
|
*/
|
||||||
class PluginLoader extends Base
|
class Loader extends \Core\Base
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Schema version table for plugins
|
* Schema version table for plugins
|
||||||
@@ -27,8 +28,8 @@ class PluginLoader extends Base
|
|||||||
*/
|
*/
|
||||||
public function scan()
|
public function scan()
|
||||||
{
|
{
|
||||||
if (file_exists(__DIR__.'/../../plugins')) {
|
if (file_exists(__DIR__.'/../../../plugins')) {
|
||||||
$dir = new DirectoryIterator(__DIR__.'/../../plugins');
|
$dir = new DirectoryIterator(__DIR__.'/../../../plugins');
|
||||||
|
|
||||||
foreach ($dir as $fileinfo) {
|
foreach ($dir as $fileinfo) {
|
||||||
if (! $fileinfo->isDot() && $fileinfo->isDir()) {
|
if (! $fileinfo->isDot() && $fileinfo->isDir()) {
|
||||||
@@ -63,7 +64,7 @@ class PluginLoader extends Base
|
|||||||
*/
|
*/
|
||||||
public function loadSchema($plugin)
|
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)) {
|
if (file_exists($filename)) {
|
||||||
require($filename);
|
require($filename);
|
||||||
@@ -33,5 +33,5 @@ if (ENABLE_URL_REWRITE) {
|
|||||||
require __DIR__.'/routes.php';
|
require __DIR__.'/routes.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
$plugin = new Core\PluginLoader($container);
|
$plugin = new Core\Plugin\Loader($container);
|
||||||
$plugin->scan();
|
$plugin->scan();
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ Example of `Plugin.php` file (`plugins/Foobar/Plugin.php`):
|
|||||||
|
|
||||||
namespace Plugin\Foobar;
|
namespace Plugin\Foobar;
|
||||||
|
|
||||||
use Core\PluginBase;
|
use Core\Plugin\Base;
|
||||||
|
|
||||||
class Plugin extends PluginBase
|
class Plugin extends Plugin\Base
|
||||||
{
|
{
|
||||||
public function initialize()
|
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.
|
The only required method is `initialize()`. This method is called for each request when the plugin is loaded.
|
||||||
|
|
||||||
Plugin methods
|
Plugin methods
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
Available methods from `PluginBase`:
|
Available methods from `Plugin\Base`:
|
||||||
|
|
||||||
- `initialize()`: Executed when the plugin is loaded
|
- `initialize()`: Executed when the plugin is loaded
|
||||||
- `getClasses()`: Return all classes that should be stored in the dependency injection container
|
- `getClasses()`: Return all classes that should be stored in the dependency injection container
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once __DIR__.'/../Base.php';
|
require_once __DIR__.'/../../Base.php';
|
||||||
|
|
||||||
use Core\PluginLoader;
|
use Core\Plugin\Loader;
|
||||||
|
|
||||||
class PluginLoaderTest extends Base
|
class LoaderTest extends Base
|
||||||
{
|
{
|
||||||
public function testGetSchemaVersion()
|
public function testGetSchemaVersion()
|
||||||
{
|
{
|
||||||
$p = new PluginLoader($this->container);
|
$p = new Loader($this->container);
|
||||||
$this->assertEquals(0, $p->getSchemaVersion('not_found'));
|
$this->assertEquals(0, $p->getSchemaVersion('not_found'));
|
||||||
|
|
||||||
$this->assertTrue($p->setSchemaVersion('plugin1', 1));
|
$this->assertTrue($p->setSchemaVersion('plugin1', 1));
|
||||||
Reference in New Issue
Block a user