Minor code improvements
This commit is contained in:
parent
3b6984dbd7
commit
c0639ccef6
2 changed files with 19 additions and 22 deletions
|
@ -110,7 +110,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
|
||||||
*/
|
*/
|
||||||
protected function configEnabled()
|
protected function configEnabled()
|
||||||
{
|
{
|
||||||
$pluginEnabled = $this->getPico()->getConfig(get_called_class() . '.enabled');
|
$pluginEnabled = $this->getPico()->getConfig(static::class . '.enabled');
|
||||||
if ($pluginEnabled !== null) {
|
if ($pluginEnabled !== null) {
|
||||||
$this->setEnabled($pluginEnabled);
|
$this->setEnabled($pluginEnabled);
|
||||||
} else {
|
} else {
|
||||||
|
@ -186,7 +186,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
|
||||||
*/
|
*/
|
||||||
public function getPluginConfig($configName = null, $default = null)
|
public function getPluginConfig($configName = null, $default = null)
|
||||||
{
|
{
|
||||||
$pluginConfig = $this->getPico()->getConfig(get_called_class(), []);
|
$pluginConfig = $this->getPico()->getConfig(static::class, []);
|
||||||
|
|
||||||
if ($configName === null) {
|
if ($configName === null) {
|
||||||
return $pluginConfig;
|
return $pluginConfig;
|
||||||
|
@ -215,7 +215,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
|
||||||
|
|
||||||
throw new BadMethodCallException(
|
throw new BadMethodCallException(
|
||||||
'Call to undefined method ' . get_class($this->getPico()) . '::' . $methodName . '() '
|
'Call to undefined method ' . get_class($this->getPico()) . '::' . $methodName . '() '
|
||||||
. 'through ' . get_called_class() . '::__call()'
|
. 'through ' . static::class . '::__call()'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
|
||||||
$plugin = $this->getPico()->getPlugin($pluginName);
|
$plugin = $this->getPico()->getPlugin($pluginName);
|
||||||
} catch (RuntimeException $e) {
|
} catch (RuntimeException $e) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Unable to enable plugin '" . get_called_class() . "': "
|
"Unable to enable plugin '" . static::class . "': "
|
||||||
. "Required plugin '" . $pluginName . "' not found"
|
. "Required plugin '" . $pluginName . "' not found"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -247,13 +247,13 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
|
||||||
$plugin->setEnabled(true, true, true);
|
$plugin->setEnabled(true, true, true);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Unable to enable plugin '" . get_called_class() . "': "
|
"Unable to enable plugin '" . static::class . "': "
|
||||||
. "Required plugin '" . $pluginName . "' was disabled manually"
|
. "Required plugin '" . $pluginName . "' was disabled manually"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Unable to enable plugin '" . get_called_class() . "': "
|
"Unable to enable plugin '" . static::class . "': "
|
||||||
. "Required plugin '" . $pluginName . "' is disabled"
|
. "Required plugin '" . $pluginName . "' is disabled"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
|
||||||
$plugin->setEnabled(false, true, true);
|
$plugin->setEnabled(false, true, true);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Unable to disable plugin '" . get_called_class() . "': "
|
"Unable to disable plugin '" . static::class . "': "
|
||||||
. "Required by manually enabled plugin '" . $pluginName . "'"
|
. "Required by manually enabled plugin '" . $pluginName . "'"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
|
||||||
$dependantsList = 'plugin' . ((count($dependants) > 1) ? 's' : '') . ' '
|
$dependantsList = 'plugin' . ((count($dependants) > 1) ? 's' : '') . ' '
|
||||||
. "'" . implode("', '", array_keys($dependants)) . "'";
|
. "'" . implode("', '", array_keys($dependants)) . "'";
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Unable to disable plugin '" . get_called_class() . "': "
|
"Unable to disable plugin '" . static::class . "': "
|
||||||
. "Required by " . $dependantsList
|
. "Required by " . $dependantsList
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
|
||||||
// only plugins which implement PicoPluginInterface support dependencies
|
// only plugins which implement PicoPluginInterface support dependencies
|
||||||
if ($plugin instanceof PicoPluginInterface) {
|
if ($plugin instanceof PicoPluginInterface) {
|
||||||
$dependencies = $plugin->getDependencies();
|
$dependencies = $plugin->getDependencies();
|
||||||
if (in_array(get_called_class(), $dependencies)) {
|
if (in_array(static::class, $dependencies)) {
|
||||||
$this->dependants[$pluginName] = $plugin;
|
$this->dependants[$pluginName] = $plugin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ abstract class AbstractPicoPlugin implements PicoPluginInterface
|
||||||
|
|
||||||
if (!$this->nativePlugin && ($pluginApiVersion > $picoApiVersion)) {
|
if (!$this->nativePlugin && ($pluginApiVersion > $picoApiVersion)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Unable to enable plugin '" . get_called_class() . "': The plugin's API (version "
|
"Unable to enable plugin '" . static::class . "': The plugin's API (version "
|
||||||
. $pluginApiVersion . ") isn't compatible with Pico's API (version " . $picoApiVersion . ")"
|
. $pluginApiVersion . ") isn't compatible with Pico's API (version " . $picoApiVersion . ")"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
21
lib/Pico.php
21
lib/Pico.php
|
@ -575,7 +575,7 @@ class Pico
|
||||||
|
|
||||||
if (!isset($this->plugins['PicoDeprecated']) && (count($this->plugins) !== count($this->nativePlugins))) {
|
if (!isset($this->plugins['PicoDeprecated']) && (count($this->plugins) !== count($this->nativePlugins))) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Plugins using an older API than version " . static::API_VERSION . " found, "
|
"Plugins using an older API than version " . self::API_VERSION . " found, "
|
||||||
. "but PicoDeprecated isn't loaded"
|
. "but PicoDeprecated isn't loaded"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -631,7 +631,7 @@ class Pico
|
||||||
|
|
||||||
$this->plugins[$className] = $plugin;
|
$this->plugins[$className] = $plugin;
|
||||||
|
|
||||||
if (defined($className . '::API_VERSION') && ($className::API_VERSION >= static::API_VERSION)) {
|
if (defined($className . '::API_VERSION') && ($className::API_VERSION >= self::API_VERSION)) {
|
||||||
$this->nativePlugins[$className] = $plugin;
|
$this->nativePlugins[$className] = $plugin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -668,12 +668,9 @@ class Pico
|
||||||
protected function loadLocalPlugins(array $pluginBlacklist = []): void
|
protected function loadLocalPlugins(array $pluginBlacklist = []): void
|
||||||
{
|
{
|
||||||
// scope isolated require()
|
// scope isolated require()
|
||||||
$includeClosure = function ($pluginFile) {
|
$includeClosure = static function ($pluginFile) {
|
||||||
require($pluginFile);
|
require($pluginFile);
|
||||||
};
|
};
|
||||||
if (PHP_VERSION_ID >= 50400) {
|
|
||||||
$includeClosure = $includeClosure->bindTo(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
$pluginBlacklist = array_fill_keys($pluginBlacklist, true);
|
$pluginBlacklist = array_fill_keys($pluginBlacklist, true);
|
||||||
|
|
||||||
|
@ -714,7 +711,7 @@ class Pico
|
||||||
$this->plugins[$className] = $plugin;
|
$this->plugins[$className] = $plugin;
|
||||||
|
|
||||||
if ($plugin instanceof PicoPluginInterface) {
|
if ($plugin instanceof PicoPluginInterface) {
|
||||||
if (defined($className . '::API_VERSION') && ($className::API_VERSION >= static::API_VERSION)) {
|
if (defined($className . '::API_VERSION') && ($className::API_VERSION >= self::API_VERSION)) {
|
||||||
$this->nativePlugins[$className] = $plugin;
|
$this->nativePlugins[$className] = $plugin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -780,7 +777,7 @@ class Pico
|
||||||
|
|
||||||
$this->plugins[$className] = $plugin;
|
$this->plugins[$className] = $plugin;
|
||||||
|
|
||||||
if (defined($className . '::API_VERSION') && ($className::API_VERSION >= static::API_VERSION)) {
|
if (defined($className . '::API_VERSION') && ($className::API_VERSION >= self::API_VERSION)) {
|
||||||
$this->nativePlugins[$className] = $plugin;
|
$this->nativePlugins[$className] = $plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1172,10 +1169,10 @@ class Pico
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for theme compatibility
|
// check for theme compatibility
|
||||||
if (!isset($this->plugins['PicoDeprecated']) && ($this->themeApiVersion < static::API_VERSION)) {
|
if (!isset($this->plugins['PicoDeprecated']) && ($this->themeApiVersion < self::API_VERSION)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
'Current theme "' . $this->theme . '" uses API version ' . $this->themeApiVersion . ', but Pico '
|
'Current theme "' . $this->theme . '" uses API version ' . $this->themeApiVersion . ', but Pico '
|
||||||
. 'provides API version ' . static::API_VERSION . ' and PicoDeprecated isn\'t loaded'
|
. 'provides API version ' . self::API_VERSION . ' and PicoDeprecated isn\'t loaded'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1651,7 +1648,7 @@ class Pico
|
||||||
$variables = [];
|
$variables = [];
|
||||||
|
|
||||||
// replace %version%
|
// replace %version%
|
||||||
$variables['%version%'] = static::VERSION;
|
$variables['%version%'] = self::VERSION;
|
||||||
|
|
||||||
// replace %site_title%
|
// replace %site_title%
|
||||||
$variables['%site_title%'] = $this->getConfig('site_title');
|
$variables['%site_title%'] = $this->getConfig('site_title');
|
||||||
|
@ -2209,7 +2206,7 @@ class Pico
|
||||||
'previous_page' => $this->previousPage,
|
'previous_page' => $this->previousPage,
|
||||||
'current_page' => $this->currentPage,
|
'current_page' => $this->currentPage,
|
||||||
'next_page' => $this->nextPage,
|
'next_page' => $this->nextPage,
|
||||||
'version' => static::VERSION,
|
'version' => self::VERSION,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue