Rename IPicoPlugin to PicoPluginInterface
This commit is contained in:
parent
4821454ad5
commit
70f187fb45
5 changed files with 31 additions and 128 deletions
|
@ -20,7 +20,7 @@
|
|||
"autoload": {
|
||||
"files": [
|
||||
"lib/Pico.php",
|
||||
"lib/IPicoPlugin.php",
|
||||
"lib/PicoPluginInterface.php",
|
||||
"lib/AbstractPicoPlugin.php"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -3,21 +3,21 @@
|
|||
/**
|
||||
* Abstract class to extend from when implementing a Pico plugin
|
||||
*
|
||||
* @see IPicoPlugin
|
||||
* @see PicoPluginInterface
|
||||
*
|
||||
* @author Daniel Rudolf
|
||||
* @link http://picocms.org
|
||||
* @license http://opensource.org/licenses/MIT
|
||||
* @version 1.0
|
||||
*/
|
||||
abstract class AbstractPicoPlugin implements IPicoPlugin
|
||||
abstract class AbstractPicoPlugin implements PicoPluginInterface
|
||||
{
|
||||
/**
|
||||
* Current instance of Pico
|
||||
*
|
||||
* @var Pico
|
||||
* @see IPicoPlugin::__construct()
|
||||
* @see IPicoPlugin::getPico()
|
||||
* @see PicoPluginInterface::__construct()
|
||||
* @see PicoPluginInterface::getPico()
|
||||
*/
|
||||
private $pico;
|
||||
|
||||
|
@ -25,8 +25,8 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
* Boolean indicating if this plugin is enabled (true) or disabled (false)
|
||||
*
|
||||
* @var boolean
|
||||
* @see IPicoPlugin::isEnabled()
|
||||
* @see IPicoPlugin::setEnabled()
|
||||
* @see PicoPluginInterface::isEnabled()
|
||||
* @see PicoPluginInterface::setEnabled()
|
||||
*/
|
||||
protected $enabled = true;
|
||||
|
||||
|
@ -34,7 +34,7 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
* Boolean indicating if this plugin was ever enabled/disabled manually
|
||||
*
|
||||
* @var boolean
|
||||
* @see IPicoPlugin::isStatusChanged()
|
||||
* @see PicoPluginInterface::isStatusChanged()
|
||||
*/
|
||||
protected $statusChanged = false;
|
||||
|
||||
|
@ -42,7 +42,7 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
* List of plugins this plugin depends on
|
||||
*
|
||||
* @var array<string>
|
||||
* @see IPicoPlugin::getDependencies()
|
||||
* @see PicoPluginInterface::getDependencies()
|
||||
* @see AbstractPicoPlugin::checkDependencies()
|
||||
*/
|
||||
protected $dependsOn = array();
|
||||
|
@ -51,13 +51,13 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
* List of plugin which depend on this plugin
|
||||
*
|
||||
* @var array<object>
|
||||
* @see IPicoPlugin::getDependants()
|
||||
* @see PicoPluginInterface::getDependants()
|
||||
* @see AbstractPicoPlugin::checkDependants()
|
||||
*/
|
||||
private $dependants;
|
||||
|
||||
/**
|
||||
* @see IPicoPlugin::__construct()
|
||||
* @see PicoPluginInterface::__construct()
|
||||
*/
|
||||
public function __construct(Pico $pico)
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
}
|
||||
|
||||
/**
|
||||
* @see IPicoPlugin::handleEvent()
|
||||
* @see PicoPluginInterface::handleEvent()
|
||||
*/
|
||||
public function handleEvent($eventName, array $params)
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
}
|
||||
|
||||
/**
|
||||
* @see IPicoPlugin::setEnabled()
|
||||
* @see PicoPluginInterface::setEnabled()
|
||||
*/
|
||||
public function setEnabled($enabled, $recursive = true, $auto = false)
|
||||
{
|
||||
|
@ -100,7 +100,7 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
}
|
||||
|
||||
/**
|
||||
* @see IPicoPlugin::isEnabled()
|
||||
* @see PicoPluginInterface::isEnabled()
|
||||
*/
|
||||
public function isEnabled()
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
}
|
||||
|
||||
/**
|
||||
* @see IPicoPlugin::isStatusChanged()
|
||||
* @see PicoPluginInterface::isStatusChanged()
|
||||
*/
|
||||
public function isStatusChanged()
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
}
|
||||
|
||||
/**
|
||||
* @see IPicoPlugin::getPico()
|
||||
* @see PicoPluginInterface::getPico()
|
||||
*/
|
||||
public function getPico()
|
||||
{
|
||||
|
@ -161,8 +161,8 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
);
|
||||
}
|
||||
|
||||
// plugins which don't implement IPicoPlugin are always enabled
|
||||
if (is_a($plugin, 'IPicoPlugin') && !$plugin->isEnabled()) {
|
||||
// plugins which don't implement PicoPluginInterface are always enabled
|
||||
if (is_a($plugin, 'PicoPluginInterface') && !$plugin->isEnabled()) {
|
||||
if ($recursive) {
|
||||
if (!$plugin->isStatusChanged()) {
|
||||
$plugin->setEnabled(true, true, true);
|
||||
|
@ -183,7 +183,7 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
}
|
||||
|
||||
/**
|
||||
* @see IPicoPlugin::getDependencies()
|
||||
* @see PicoPluginInterface::getDependencies()
|
||||
*/
|
||||
public function getDependencies()
|
||||
{
|
||||
|
@ -226,15 +226,15 @@ abstract class AbstractPicoPlugin implements IPicoPlugin
|
|||
}
|
||||
|
||||
/**
|
||||
* @see IPicoPlugin::getDependants()
|
||||
* @see PicoPluginInterface::getDependants()
|
||||
*/
|
||||
public function getDependants()
|
||||
{
|
||||
if ($this->dependants === null) {
|
||||
$this->dependants = array();
|
||||
foreach ($this->getPlugins() as $pluginName => $plugin) {
|
||||
// only plugins which implement IPicoPlugin support dependencies
|
||||
if (is_a($plugin, 'IPicoPlugin')) {
|
||||
// only plugins which implement PicoPluginInterface support dependencies
|
||||
if (is_a($plugin, 'PicoPluginInterface')) {
|
||||
$dependencies = $plugin->getDependencies();
|
||||
if (in_array(get_called_class(), $dependencies)) {
|
||||
$this->dependants[$pluginName] = $plugin;
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Common interface for Pico plugins
|
||||
*
|
||||
* For a list of supported events see {@link DummyPlugin}; you can use
|
||||
* {@link DummyPlugin} as template for new plugins. For a list of deprecated
|
||||
* events see {@link PicoDeprecated}.
|
||||
*
|
||||
* You SHOULD NOT use deprecated events when implementing this interface.
|
||||
* Deprecated events are triggered by the {@link PicoDeprecated} plugin, if
|
||||
* plugins which don't implement this interface are loaded. You can take
|
||||
* advantage from this behaviour if you want to do something only when old
|
||||
* plugins are loaded. Consequently the old events are never triggered when
|
||||
* your plugin is implementing this interface and no old plugins are present.
|
||||
*
|
||||
* If you're developing a new plugin, you MUST implement IPicoPlugin. If
|
||||
* you're the developer of an old plugin, it is STRONGLY RECOMMENDED to use
|
||||
* the events introduced in Pico 1.0 when releasing a new version of your
|
||||
* plugin. If you want to use any of the new events, you MUST implement
|
||||
* IPicoPlugin and update all other events you use.
|
||||
*
|
||||
* @author Daniel Rudolf
|
||||
* @link http://picocms.org
|
||||
* @license http://opensource.org/licenses/MIT
|
||||
* @version 1.0
|
||||
*/
|
||||
interface IPicoPlugin
|
||||
{
|
||||
/**
|
||||
* Constructs a new instance of a Pico plugin
|
||||
*
|
||||
* @param Pico $pico current instance of Pico
|
||||
*/
|
||||
public function __construct(Pico $pico);
|
||||
|
||||
/**
|
||||
* Handles a event that was triggered by Pico
|
||||
*
|
||||
* @param string $eventName name of the triggered event
|
||||
* @param array $params passed parameters
|
||||
* @return void
|
||||
*/
|
||||
public function handleEvent($eventName, array $params);
|
||||
|
||||
/**
|
||||
* Enables or disables this plugin
|
||||
*
|
||||
* @param boolean $enabled enable (true) or disable (false) this plugin
|
||||
* @param boolean $recursive when true, enable or disable recursively
|
||||
* In other words, if you enable a plugin, all required plugins are
|
||||
* enabled, too. When disabling a plugin, all depending plugins are
|
||||
* disabled likewise. Recursive operations are only performed as long
|
||||
* as a plugin wasn't enabled/disabled manually. This parameter is
|
||||
* optional and defaults to true.
|
||||
* @param boolean $auto enable or disable to fulfill a dependency
|
||||
* This parameter is optional and defaults to false.
|
||||
* @return void
|
||||
* @throws RuntimeException thrown when a dependency fails
|
||||
*/
|
||||
public function setEnabled($enabled, $recursive = true, $auto = false);
|
||||
|
||||
/**
|
||||
* Returns true if this plugin is enabled, false otherwise
|
||||
*
|
||||
* @return boolean plugin is enabled (true) or disabled (false)
|
||||
*/
|
||||
public function isEnabled();
|
||||
|
||||
/**
|
||||
* Returns true if the plugin was ever enabled/disabled manually
|
||||
*
|
||||
* @return boolean plugin is in its default state (true), false otherwise
|
||||
*/
|
||||
public function isStatusChanged();
|
||||
|
||||
/**
|
||||
* Returns a list of names of plugins required by this plugin
|
||||
*
|
||||
* @return array<string> required plugins
|
||||
*/
|
||||
public function getDependencies();
|
||||
|
||||
/**
|
||||
* Returns a list of plugins which depend on this plugin
|
||||
*
|
||||
* @return array<object> dependant plugins
|
||||
*/
|
||||
public function getDependants();
|
||||
|
||||
/**
|
||||
* Returns the plugins instance of Pico
|
||||
*
|
||||
* @return Pico the plugins instance of Pico
|
||||
*/
|
||||
public function getPico();
|
||||
}
|
10
lib/Pico.php
10
lib/Pico.php
|
@ -258,8 +258,8 @@ class Pico
|
|||
/**
|
||||
* Returns the instance of a named plugin
|
||||
*
|
||||
* Plugins SHOULD implement {@link IPicoPlugin}, but you MUST NOT rely on
|
||||
* it. For more information see {@link IPicoPlugin}.
|
||||
* Plugins SHOULD implement {@link PicoPluginInterface}, but you MUST NOT
|
||||
* rely on it. For more information see {@link PicoPluginInterface}.
|
||||
*
|
||||
* @see Pico::loadPlugins()
|
||||
* @param string $pluginName name of the plugin
|
||||
|
@ -922,7 +922,7 @@ class Pico
|
|||
}
|
||||
|
||||
/**
|
||||
* Triggers events on plugins which implement {@link IPicoPlugin}
|
||||
* Triggers events on plugins which implement {@link PicoPluginInterface}
|
||||
*
|
||||
* Deprecated events (as used by plugins not implementing
|
||||
* {@link IPocPlugin}) are triggered by {@link PicoDeprecated}.
|
||||
|
@ -934,10 +934,10 @@ class Pico
|
|||
protected function triggerEvent($eventName, array $params = array())
|
||||
{
|
||||
foreach ($this->plugins as $plugin) {
|
||||
// only trigger events for plugins that implement IPicoPlugin
|
||||
// only trigger events for plugins that implement PicoPluginInterface
|
||||
// deprecated events (plugins for Pico 0.9 and older) will be
|
||||
// triggered by the `PicoPluginDeprecated` plugin
|
||||
if (is_a($plugin, 'IPicoPlugin')) {
|
||||
if (is_a($plugin, 'PicoPluginInterface')) {
|
||||
$plugin->handleEvent($eventName, $params);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*
|
||||
* This plugin exists for backward compatibility and is disabled by default.
|
||||
* It gets automatically enabled when a plugin which doesn't implement
|
||||
* {@link IPicoPlugin} is loaded. This plugin mainly triggers deprecated
|
||||
* events, but also automatically enables {@link PicoParsePagesContent} and
|
||||
* {@link PicoPluginInterface} is loaded. This plugin triggers deprecated
|
||||
* events and automatically enables {@link PicoParsePagesContent} and
|
||||
* {@link PicoExcerpt}. These plugins heavily impact Picos performance! You
|
||||
* can disable this plugin by calling {@link PicoDeprecated::setEnabled()}.
|
||||
*
|
||||
|
@ -68,8 +68,8 @@ class PicoDeprecated extends AbstractPicoPlugin
|
|||
public function onPluginsLoaded(&$plugins)
|
||||
{
|
||||
foreach ($plugins as $plugin) {
|
||||
if (!is_a($plugin, 'IPicoPlugin')) {
|
||||
// the plugin doesn't implement IPicoPlugin; it uses deprecated events
|
||||
if (!is_a($plugin, 'PicoPluginInterface')) {
|
||||
// the plugin doesn't implement PicoPluginInterface; it uses deprecated events
|
||||
// enable PicoDeprecated if it hasn't be explicitly enabled/disabled yet
|
||||
if (!$this->isStatusChanged()) {
|
||||
$this->setEnabled(true, true, true);
|
||||
|
|
Loading…
Reference in a new issue