namespacing: \Shaarli\Plugin\PluginManager

Signed-off-by: VirtualTam <virtualtam@flibidi.net>
This commit is contained in:
VirtualTam 2018-12-04 00:26:50 +01:00
parent 349b014401
commit e185038834
22 changed files with 65 additions and 41 deletions

View File

@ -1,4 +1,8 @@
<?php
namespace Shaarli\Plugin;
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\Exception\PluginFileNotFoundException;
/**
* Class PluginManager
@ -9,12 +13,14 @@ class PluginManager
{
/**
* List of authorized plugins from configuration file.
*
* @var array $authorizedPlugins
*/
private $authorizedPlugins;
/**
* List of loaded plugins.
*
* @var array $loadedPlugins
*/
private $loadedPlugins = array();
@ -31,12 +37,14 @@ class PluginManager
/**
* Plugins subdirectory.
*
* @var string $PLUGINS_PATH
*/
public static $PLUGINS_PATH = 'plugins';
/**
* Plugins meta files extension.
*
* @var string $META_EXT
*/
public static $META_EXT = 'meta';
@ -84,9 +92,9 @@ class PluginManager
/**
* Execute all plugins registered hook.
*
* @param string $hook name of the hook to trigger.
* @param array $data list of data to manipulate passed by reference.
* @param array $params additional parameters such as page target.
* @param string $hook name of the hook to trigger.
* @param array $data list of data to manipulate passed by reference.
* @param array $params additional parameters such as page target.
*
* @return void
*/
@ -118,7 +126,7 @@ class PluginManager
* @param string $pluginName plugin's name.
*
* @return void
* @throws PluginFileNotFoundException - plugin files not found.
* @throws \Shaarli\Plugin\Exception\PluginFileNotFoundException - plugin files not found.
*/
private function loadPlugin($dir, $pluginName)
{
@ -204,8 +212,8 @@ class PluginManager
$metaData[$plugin]['parameters'][$param]['value'] = '';
// Optional parameter description in parameter.PARAM_NAME=
if (isset($metaData[$plugin]['parameter.'. $param])) {
$metaData[$plugin]['parameters'][$param]['desc'] = t($metaData[$plugin]['parameter.'. $param]);
if (isset($metaData[$plugin]['parameter.' . $param])) {
$metaData[$plugin]['parameters'][$param]['desc'] = t($metaData[$plugin]['parameter.' . $param]);
}
}
}
@ -223,22 +231,3 @@ class PluginManager
return $this->errors;
}
}
/**
* Class PluginFileNotFoundException
*
* Raise when plugin files can't be found.
*/
class PluginFileNotFoundException extends Exception
{
/**
* Construct exception with plugin name.
* Generate message.
*
* @param string $pluginName name of the plugin not found
*/
public function __construct($pluginName)
{
$this->message = sprintf(t('Plugin "%s" files not found.'), $pluginName);
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Shaarli\Plugin\Exception;
use Exception;
/**
* Class PluginFileNotFoundException
*
* Raise when plugin files can't be found.
*/
class PluginFileNotFoundException extends Exception
{
/**
* Construct exception with plugin name.
* Generate message.
*
* @param string $pluginName name of the plugin not found
*/
public function __construct($pluginName)
{
$this->message = sprintf(t('Plugin "%s" files not found.'), $pluginName);
}
}

View File

@ -46,6 +46,8 @@
"Shaarli\\Feed\\": "application/feed",
"Shaarli\\Http\\": "application/http",
"Shaarli\\Netscape\\": "application/netscape",
"Shaarli\\Plugin\\": "application/plugin",
"Shaarli\\Plugin\\Exception\\": "application/plugin/exception",
"Shaarli\\Render\\": "application/render",
"Shaarli\\Security\\": "application/security",
"Shaarli\\Updater\\": "application/updater",

View File

@ -65,7 +65,6 @@ require_once 'application/updater/UpdaterUtils.php';
require_once 'application/FileUtils.php';
require_once 'application/TimeZone.php';
require_once 'application/Utils.php';
require_once 'application/PluginManager.php';
use \Shaarli\ApplicationUtils;
use \Shaarli\Bookmark\Exception\LinkNotFoundException;
@ -76,6 +75,7 @@ use \Shaarli\Feed\FeedBuilder;
use \Shaarli\History;
use \Shaarli\Languages;
use \Shaarli\Netscape\NetscapeBookmarkUtils;
use \Shaarli\Plugin\PluginManager;
use \Shaarli\Render\PageBuilder;
use \Shaarli\Render\ThemeUtils;
use \Shaarli\Router;

View File

@ -5,6 +5,8 @@
* Add an icon in the link list for archive.org.
*/
use Shaarli\Plugin\PluginManager;
/**
* Add archive.org icon to link_plugin when rendering linklist.
*

View File

@ -15,6 +15,7 @@
*/
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/**

View File

@ -5,6 +5,7 @@
*/
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/**

View File

@ -7,6 +7,7 @@
*/
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/*

View File

@ -4,6 +4,8 @@
* Adds tracking code on each page.
*/
use Shaarli\Plugin\PluginManager;
/**
* Initialization function.
* It will be called when the plugin is loaded.

View File

@ -6,6 +6,7 @@
* Note: this plugin adds jQuery.
*/
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/**

View File

@ -12,6 +12,7 @@
use pubsubhubbub\publisher\Publisher;
use Shaarli\Config\ConfigManager;
use Shaarli\Feed\FeedBuilder;
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/**

View File

@ -5,6 +5,7 @@
* Display a QRCode icon in link list.
*/
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/**

View File

@ -6,6 +6,7 @@
require_once 'WallabagInstance.php';
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
/**
* Init function, return an error if the server is not set.

View File

@ -1,16 +1,12 @@
<?php
namespace Shaarli\Plugin;
use Shaarli\Config\ConfigManager;
/**
* Plugin Manager tests
*/
require_once 'application/PluginManager.php';
/**
* Unit tests for Plugins
*/
class PluginManagerTest extends PHPUnit_Framework_TestCase
class PluginManagerTest extends \PHPUnit\Framework\TestCase
{
/**
* Path to tests plugin.

View File

@ -1,19 +1,14 @@
<?php
/**
* PluginPlayvideosTest.php
*/
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
require_once 'application/Router.php';
/**
* Class PluginAddlinkTest
* Unit test for the Addlink toolbar plugin
*/
class PluginAddlinkTest extends PHPUnit_Framework_TestCase
class PluginAddlinkTest extends \PHPUnit\Framework\TestCase
{
/**
* Reset plugin path.

View File

@ -4,6 +4,8 @@
* PluginArchiveorgTest.php
*/
use Shaarli\Plugin\PluginManager;
require_once 'plugins/archiveorg/archiveorg.php';
/**

View File

@ -2,6 +2,7 @@
use Shaarli\Bookmark\LinkDB;
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
require_once 'plugins/isso/isso.php';

View File

@ -1,5 +1,6 @@
<?php
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
/**
* PluginMarkdownTest.php

View File

@ -4,6 +4,7 @@
* PluginPlayvideosTest.php
*/
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
require_once 'plugins/playvideos/playvideos.php';

View File

@ -1,5 +1,6 @@
<?php
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
require_once 'plugins/pubsubhubbub/pubsubhubbub.php';

View File

@ -3,6 +3,7 @@
* PluginQrcodeTest.php
*/
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
require_once 'plugins/qrcode/qrcode.php';

View File

@ -1,5 +1,6 @@
<?php
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
/**
* PluginWallabagTest.php.php
@ -11,7 +12,7 @@ require_once 'plugins/wallabag/wallabag.php';
* Class PluginWallabagTest
* Unit test for the Wallabag plugin
*/
class PluginWallabagTest extends PHPUnit_Framework_TestCase
class PluginWallabagTest extends \PHPUnit\Framework\TestCase
{
/**
* Reset plugin path