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 @@ public function load($authorizedPlugins)
/**
* 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 @@ public function executeHooks($hook, &$data, $params = array())
* @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 @@ public function getPluginsMeta()
$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 @@ public function getErrors()
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/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\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 @@
* Class PluginWallabagTest
* Unit test for the Wallabag plugin
*/
class PluginWallabagTest extends PHPUnit_Framework_TestCase
class PluginWallabagTest extends \PHPUnit\Framework\TestCase
{
/**
* Reset plugin path