From e8341154e8b142677e4e37229e4cd584a7bde054 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 29 Mar 2020 15:12:01 +0200 Subject: [PATCH 01/28] Kick-start development of Pico 3.0 --- PicoDeprecated.php | 2 +- composer.json | 3 ++- lib/AbstractPicoCompatPlugin.php | 2 +- lib/AbstractPicoPluginApiCompatPlugin.php | 2 +- lib/PicoCompatPluginInterface.php | 2 +- lib/PicoPluginApiCompatPluginInterface.php | 2 +- plugins/PicoMainCompatPlugin.php | 2 +- plugins/PicoPluginApi0CompatPlugin.php | 2 +- plugins/PicoPluginApi1CompatPlugin.php | 2 +- plugins/PicoPluginApi2CompatPlugin.php | 2 +- plugins/PicoThemeApi0CompatPlugin.php | 2 +- plugins/PicoThemeApi1CompatPlugin.php | 2 +- plugins/PicoThemeApi2CompatPlugin.php | 2 +- 13 files changed, 14 insertions(+), 13 deletions(-) diff --git a/PicoDeprecated.php b/PicoDeprecated.php index 9334661..dcdf8a8 100644 --- a/PicoDeprecated.php +++ b/PicoDeprecated.php @@ -33,7 +33,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ class PicoDeprecated extends AbstractPicoPlugin { diff --git a/composer.json b/composer.json index 4115164..daf56bc 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.1.x-dev" + "dev-master": "2.1.x-dev", + "dev-pico-3.0": "3.0.x-dev" } } } diff --git a/lib/AbstractPicoCompatPlugin.php b/lib/AbstractPicoCompatPlugin.php index 1d3961a..112b617 100644 --- a/lib/AbstractPicoCompatPlugin.php +++ b/lib/AbstractPicoCompatPlugin.php @@ -22,7 +22,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ abstract class AbstractPicoCompatPlugin implements PicoCompatPluginInterface { diff --git a/lib/AbstractPicoPluginApiCompatPlugin.php b/lib/AbstractPicoPluginApiCompatPlugin.php index af32b2f..f41df8d 100644 --- a/lib/AbstractPicoPluginApiCompatPlugin.php +++ b/lib/AbstractPicoPluginApiCompatPlugin.php @@ -22,7 +22,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ abstract class AbstractPicoPluginApiCompatPlugin extends AbstractPicoCompatPlugin implements PicoPluginApiCompatPluginInterface diff --git a/lib/PicoCompatPluginInterface.php b/lib/PicoCompatPluginInterface.php index 6ede84f..7492b19 100644 --- a/lib/PicoCompatPluginInterface.php +++ b/lib/PicoCompatPluginInterface.php @@ -16,7 +16,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ interface PicoCompatPluginInterface { diff --git a/lib/PicoPluginApiCompatPluginInterface.php b/lib/PicoPluginApiCompatPluginInterface.php index 5e71768..e2e7c1e 100644 --- a/lib/PicoPluginApiCompatPluginInterface.php +++ b/lib/PicoPluginApiCompatPluginInterface.php @@ -16,7 +16,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ interface PicoPluginApiCompatPluginInterface extends PicoCompatPluginInterface { diff --git a/plugins/PicoMainCompatPlugin.php b/plugins/PicoMainCompatPlugin.php index 683aad9..6c84f3c 100644 --- a/plugins/PicoMainCompatPlugin.php +++ b/plugins/PicoMainCompatPlugin.php @@ -24,7 +24,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ class PicoMainCompatPlugin extends AbstractPicoCompatPlugin { diff --git a/plugins/PicoPluginApi0CompatPlugin.php b/plugins/PicoPluginApi0CompatPlugin.php index d459524..edf676a 100644 --- a/plugins/PicoPluginApi0CompatPlugin.php +++ b/plugins/PicoPluginApi0CompatPlugin.php @@ -25,7 +25,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ class PicoPluginApi0CompatPlugin extends AbstractPicoPluginApiCompatPlugin { diff --git a/plugins/PicoPluginApi1CompatPlugin.php b/plugins/PicoPluginApi1CompatPlugin.php index ea886df..bc0edd3 100644 --- a/plugins/PicoPluginApi1CompatPlugin.php +++ b/plugins/PicoPluginApi1CompatPlugin.php @@ -25,7 +25,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ class PicoPluginApi1CompatPlugin extends AbstractPicoPluginApiCompatPlugin { diff --git a/plugins/PicoPluginApi2CompatPlugin.php b/plugins/PicoPluginApi2CompatPlugin.php index a9ebbee..deacf47 100644 --- a/plugins/PicoPluginApi2CompatPlugin.php +++ b/plugins/PicoPluginApi2CompatPlugin.php @@ -25,7 +25,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ class PicoPluginApi2CompatPlugin extends AbstractPicoPluginApiCompatPlugin { diff --git a/plugins/PicoThemeApi0CompatPlugin.php b/plugins/PicoThemeApi0CompatPlugin.php index 9ed6a64..91d6fdb 100644 --- a/plugins/PicoThemeApi0CompatPlugin.php +++ b/plugins/PicoThemeApi0CompatPlugin.php @@ -31,7 +31,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ class PicoThemeApi0CompatPlugin extends AbstractPicoCompatPlugin { diff --git a/plugins/PicoThemeApi1CompatPlugin.php b/plugins/PicoThemeApi1CompatPlugin.php index f4b276b..a7250b9 100644 --- a/plugins/PicoThemeApi1CompatPlugin.php +++ b/plugins/PicoThemeApi1CompatPlugin.php @@ -25,7 +25,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ class PicoThemeApi1CompatPlugin extends AbstractPicoCompatPlugin { diff --git a/plugins/PicoThemeApi2CompatPlugin.php b/plugins/PicoThemeApi2CompatPlugin.php index 646925b..9d8bd73 100644 --- a/plugins/PicoThemeApi2CompatPlugin.php +++ b/plugins/PicoThemeApi2CompatPlugin.php @@ -25,7 +25,7 @@ * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License - * @version 2.1 + * @version 3.0 */ class PicoThemeApi2CompatPlugin extends AbstractPicoCompatPlugin { From cb4cf9189f7f2ddeb4f91591ce44fb51ec52e090 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 29 Mar 2020 15:19:22 +0200 Subject: [PATCH 02/28] Update CHANGELOG.md --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e8b9d3..4063d62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,13 @@ Pico Deprecated Changelog because they are already listed in Pico's changelog. Only functional changes and/or BC-breaking changes are listed below. +### Version 3.0.0-alpha.1 +Released: 2020-03-29 + +``` +* [New] Kick-start development of Pico 3.0 +``` + ### Version 2.1.1 Released: 2019-12-31 From 62af9ec2bbe4eb37e590abeff336dc86cbb65e55 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 29 Mar 2020 15:20:25 +0200 Subject: [PATCH 03/28] Version 3.0.0-alpha.1 ``` * [New] Kick-start development of Pico 3.0 ``` From 2f590accc5571fadb712d54d53729fbc72cd30bd Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 29 Mar 2020 16:24:39 +0200 Subject: [PATCH 04/28] Fix Travis CI trying to build PicoDeprecated 3.0 on PHP 5.x --- .travis.yml | 13 +++++-------- composer.json | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index e521bf8..12f0ccb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ -dist: trusty +os: linux +dist: bionic sudo: false language: php @@ -10,12 +11,8 @@ cache: jobs: include: # Test stage - - php: 5.3 - dist: precise - - php: 5.4 - - php: 5.5 - - php: 5.6 - php: 7.0 + dist: xenial - php: 7.1 - php: 7.2 - php: 7.3 @@ -27,8 +24,8 @@ jobs: # Release deployment stage - stage: deploy-release if: tag IS present - php: 5.3 - dist: precise + php: 7.0 + dist: xenial install: - install.sh script: diff --git a/composer.json b/composer.json index daf56bc..6408faf 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "source": "https://github.com/picocms/pico-deprecated" }, "require": { - "php": ">=5.3.0", + "php": ">=7.0.0", "picocms/pico": "self.version" }, "autoload": { From 097588e631bb32bcbfce813bf94584f883799d74 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sat, 11 Apr 2020 20:54:30 +0200 Subject: [PATCH 05/28] Move PicoDeprecated to picocms\PicoDeprecated\ namespace The PicoDeprecated class itself must remain in the root namespace, but all libraries and compat plugins can be moved to this namespace (the latter to picocms\PicoDeprecated\Plugin). --- PicoDeprecated.php | 31 ++++++---- README.md | 4 +- composer.json | 6 +- ...icoCompatPlugin.php => AbstractPlugin.php} | 21 ++++--- ...Plugin.php => AbstractPluginApiPlugin.php} | 15 ++--- ...rface.php => PluginApiPluginInterface.php} | 6 +- ...luginInterface.php => PluginInterface.php} | 9 ++- ...icoMainCompatPlugin.php => MainPlugin.php} | 15 +++-- ...0CompatPlugin.php => PluginApi0Plugin.php} | 29 +++++---- ...1CompatPlugin.php => PluginApi1Plugin.php} | 60 ++++++++++--------- ...2CompatPlugin.php => PluginApi2Plugin.php} | 22 ++++--- ...i0CompatPlugin.php => ThemeApi0Plugin.php} | 17 ++++-- ...i1CompatPlugin.php => ThemeApi1Plugin.php} | 21 ++++--- ...i2CompatPlugin.php => ThemeApi2Plugin.php} | 33 +++++----- 14 files changed, 173 insertions(+), 116 deletions(-) rename lib/{AbstractPicoCompatPlugin.php => AbstractPlugin.php} (81%) rename lib/{AbstractPicoPluginApiCompatPlugin.php => AbstractPluginApiPlugin.php} (83%) rename lib/{PicoPluginApiCompatPluginInterface.php => PluginApiPluginInterface.php} (88%) rename lib/{PicoCompatPluginInterface.php => PluginInterface.php} (92%) rename plugins/{PicoMainCompatPlugin.php => MainPlugin.php} (91%) rename plugins/{PicoPluginApi0CompatPlugin.php => PluginApi0Plugin.php} (92%) rename plugins/{PicoPluginApi1CompatPlugin.php => PluginApi1Plugin.php} (85%) rename plugins/{PicoPluginApi2CompatPlugin.php => PluginApi2Plugin.php} (89%) rename plugins/{PicoThemeApi0CompatPlugin.php => ThemeApi0Plugin.php} (76%) rename plugins/{PicoThemeApi1CompatPlugin.php => ThemeApi1Plugin.php} (91%) rename plugins/{PicoThemeApi2CompatPlugin.php => ThemeApi2Plugin.php} (88%) diff --git a/PicoDeprecated.php b/PicoDeprecated.php index dcdf8a8..3248cd0 100644 --- a/PicoDeprecated.php +++ b/PicoDeprecated.php @@ -16,6 +16,13 @@ * License-Filename: LICENSE */ +use picocms\Pico\AbstractPlugin as AbstractPicoPlugin; +use picocms\Pico\Pico; +use picocms\Pico\PluginInterface as PicoPluginInterface; +use picocms\PicoDeprecated\Plugin\MainPlugin; +use picocms\PicoDeprecated\PluginApiPluginInterface; +use picocms\PicoDeprecated\PluginInterface; + /** * Maintain backward compatibility to older Pico releases * @@ -86,7 +93,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @see PicoDeprecated::getCompatPlugins() * - * @var PicoCompatPluginInterface[] + * @var PluginInterface[] */ protected $compatPlugins = array(); @@ -101,7 +108,7 @@ public function __construct(Pico $pico) require(__DIR__ . '/vendor/autoload.php'); } - if (!class_exists('PicoMainCompatPlugin')) { + if (!class_exists(MainPlugin::class)) { die( "Cannot find PicoDeprecated's 'vendor/autoload.php'. If you're using a composer-based Pico install, " . "run `composer update`. If you're rather trying to use one of PicoDeprecated's pre-built release " @@ -133,7 +140,7 @@ public function handleEvent($eventName, array $params) if ($plugin->getApiVersion() === static::API_VERSION) { $plugin->handleEvent($eventName, $params); } - } elseif ($plugin instanceof PicoPluginApiCompatPluginInterface) { + } elseif ($plugin instanceof PluginApiPluginInterface) { $plugin->handleCustomEvent($eventName, $params); } } @@ -150,7 +157,7 @@ public function handleEvent($eventName, array $params) */ public function onPluginsLoaded(array $plugins) { - $this->loadCompatPlugin('PicoMainCompatPlugin'); + $this->loadCompatPlugin(MainPlugin::class); foreach ($plugins as $plugin) { $this->loadPlugin($plugin); @@ -221,10 +228,10 @@ public function getPlugins($apiVersion) /** * Loads a compatibility plugin * - * @param PicoCompatPluginInterface|string $plugin either the class name of - * a plugin to instantiate or a plugin instance + * @param PluginInterface|string $plugin either the class name of a plugin + * to instantiate or a plugin instance * - * @return PicoCompatPluginInterface instance of the loaded plugin + * @return PluginInterface instance of the loaded plugin */ public function loadCompatPlugin($plugin) { @@ -244,10 +251,10 @@ public function loadCompatPlugin($plugin) return $this->compatPlugins[$className]; } - if (!($plugin instanceof PicoCompatPluginInterface)) { + if (!($plugin instanceof PluginInterface)) { throw new RuntimeException( "Unable to load PicoDeprecated compatibility plugin '" . $className . "': " - . "Compatibility plugins must implement 'PicoCompatPluginInterface'" + . "Compatibility plugins must implement '" . PluginInterface::class . "'" ); } @@ -272,7 +279,7 @@ public function loadCompatPlugin($plugin) protected function loadPluginApiCompatPlugin($apiVersion) { if ($apiVersion !== static::API_VERSION) { - $this->loadCompatPlugin('PicoPluginApi' . $apiVersion . 'CompatPlugin'); + $this->loadCompatPlugin('picocms\PicoDeprecated\Plugin\PluginApi' . $apiVersion . 'Plugin'); } } @@ -284,14 +291,14 @@ protected function loadPluginApiCompatPlugin($apiVersion) protected function loadThemeApiCompatPlugin($apiVersion) { if ($apiVersion !== static::API_VERSION) { - $this->loadCompatPlugin('PicoThemeApi' . $apiVersion . 'CompatPlugin'); + $this->loadCompatPlugin('picocms\PicoDeprecated\Plugin\ThemeApi' . $apiVersion . 'Plugin'); } } /** * Returns all loaded compatibility plugins * - * @return PicoCompatPluginInterface[] list of loaded compatibility plugins + * @return PluginInterface[] list of loaded compatibility plugins */ public function getCompatPlugins() { diff --git a/README.md b/README.md index 4c3091a..db5bd59 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ Usage You can explicitly disable `PicoDeprecated` by adding `PicoDeprecated.enabled: false` to your `config/config.yml`. If you want to re-enable `PicoDeprecated`, simply remove this line from your `config/config.yml`. `PicoDeprecated` itself has no configuration options, it enables and disables all of its features depending on whether there are plugins and/or themes requiring said characteristics. -`PicoDeprecated`'s functionality is split into various so-called "compatibility plugins". There are compatibility plugins for every old API version (Pico 0.9 and earlier were using API version 0, Pico 1.0 was using API version 1 and Pico 2.0 was using API version 2; the current API version is version 3, used by Pico 2.1), one for plugins and another one for themes. Their purpose is to re-introduce characteristics plugins and themes using said API version might rely on. For example, plugin API compatibility plugins are responsible for simulating old Pico core events (like the `before_render` event used by Pico 0.9 and earlier). Theme API compatibility plugins will e.g. register old Twig variables (like the `is_front_page` Twig variable used by Pico 1.0). If you install a plugin using API version 2, the corresponding `PicoPluginApi2CompatPlugin` will be loaded. All plugin API compatibility plugins also depend on their theme counterpart, thus `PicoThemeApi2CompatPlugin` will be loaded, too. Furthermore all compatibility plugins depend on their respective API successors. +`PicoDeprecated`'s functionality is split into various so-called "compatibility plugins". There are compatibility plugins for every old API version (Pico 0.9 and earlier were using API version 0, Pico 1.0 was using API version 1 and Pico 2.0 was using API version 2; the current API version is version 3, used by Pico 2.1), one for plugins and another one for themes. Their purpose is to re-introduce characteristics plugins and themes using said API version might rely on. For example, plugin API compatibility plugins are responsible for simulating old Pico core events (like the `before_render` event used by Pico 0.9 and earlier). Theme API compatibility plugins will e.g. register old Twig variables (like the `is_front_page` Twig variable used by Pico 1.0). If you install a plugin using API version 2, the corresponding `picocms\PicoDeprecated\Plugin\PluginApi2Plugin` will be loaded. All plugin API compatibility plugins also depend on their theme counterpart, thus `picocms\PicoDeprecated\Plugin\ThemeApi2Plugin` will be loaded, too. Furthermore all compatibility plugins depend on their respective API successors. -The plugin exposes a simple API to allow other plugins to load their own compatibility plugins. As a plugin developer you may use the `PicoDeprecated::loadCompatPlugin(PicoCompatPluginInterface $compatPlugin)` method to load a custom compatibility plugin. Use `PicoDeprecated::getCompatPlugins()` to return a list of all loaded compatibility plugins. You can furthermore use the `PicoDeprecated::getPlugins(int $apiVersion)` method to return a list of all loaded Pico plugins using a particular API version. If you want to trigger a custom event on plugins using a particular API version only, use `PicoDeprecated::triggerEvent(int $apiVersion, string $eventName, array $parameters = [])`. `PicoDeprecated` furthermore triggers the custom `onPicoDeprecated(PicoDeprecated $picoDeprecated)` event. +The plugin exposes a simple API to allow other plugins to load their own compatibility plugins. As a plugin developer you may use the `PicoDeprecated::loadCompatPlugin(picocms\PicoDeprecated\PluginInterface $compatPlugin)` method to load a custom compatibility plugin. Use `PicoDeprecated::getCompatPlugins()` to return a list of all loaded compatibility plugins. You can furthermore use the `PicoDeprecated::getPlugins(int $apiVersion)` method to return a list of all loaded Pico plugins using a particular API version. If you want to trigger a custom event on plugins using a particular API version only, use `PicoDeprecated::triggerEvent(int $apiVersion, string $eventName, array $parameters = [])`. `PicoDeprecated` furthermore triggers the custom `onPicoDeprecated(PicoDeprecated $picoDeprecated)` event. Getting Help ------------ diff --git a/composer.json b/composer.json index 6408faf..ee88390 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,11 @@ "picocms/pico": "self.version" }, "autoload": { - "classmap": [ "PicoDeprecated.php", "lib/", "plugins/" ] + "psr-0": { "PicoDeprecated": "" }, + "psr-4": { + "picocms\\PicoDeprecated\\": "lib/", + "picocms\\PicoDeprecated\\Plugin\\": "plugins/" + } }, "extra": { "branch-alias": { diff --git a/lib/AbstractPicoCompatPlugin.php b/lib/AbstractPlugin.php similarity index 81% rename from lib/AbstractPicoCompatPlugin.php rename to lib/AbstractPlugin.php index 112b617..0daf79a 100644 --- a/lib/AbstractPicoCompatPlugin.php +++ b/lib/AbstractPlugin.php @@ -4,32 +4,37 @@ * in the version control history of the file, available from the following * original location: * - * + * * * SPDX-License-Identifier: MIT * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated; + +use picocms\Pico\Pico; +use PicoDeprecated; + /** * Abstract class to extend from when implementing a PicoDeprecated * compatibility plugin * - * Please refer to {@see PicoCompatPluginInterface} for more information about - * how to develop a PicoDeprecated compatibility plugin. + * Please refer to {@see PluginInterface} for more information about how to + * develop a PicoDeprecated compatibility plugin. * - * @see PicoCompatPluginInterface + * @see PluginInterface * * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -abstract class AbstractPicoCompatPlugin implements PicoCompatPluginInterface +abstract class AbstractPlugin implements PluginInterface { /** * Current instance of Pico * - * @see PicoCompatPluginInterface::getPico() + * @see PluginInterface::getPico() * * @var Pico */ @@ -38,7 +43,7 @@ abstract class AbstractPicoCompatPlugin implements PicoCompatPluginInterface /** * Instance of the main PicoDeprecated plugin * - * @see PicoCompatPluginInterface::getPicoDeprecated() + * @see PluginInterface::getPicoDeprecated() * * @var PicoDeprecated */ @@ -47,7 +52,7 @@ abstract class AbstractPicoCompatPlugin implements PicoCompatPluginInterface /** * List of plugins which this plugin depends on * - * @see PicoCompatPluginInterface::getDependencies() + * @see PluginInterface::getDependencies() * * @var string[] */ diff --git a/lib/AbstractPicoPluginApiCompatPlugin.php b/lib/AbstractPluginApiPlugin.php similarity index 83% rename from lib/AbstractPicoPluginApiCompatPlugin.php rename to lib/AbstractPluginApiPlugin.php index f41df8d..3b85696 100644 --- a/lib/AbstractPicoPluginApiCompatPlugin.php +++ b/lib/AbstractPluginApiPlugin.php @@ -4,33 +4,34 @@ * in the version control history of the file, available from the following * original location: * - * + * * * SPDX-License-Identifier: MIT * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated; + /** * Abstract class to extend from when implementing a PicoDeprecated plugin API * compatibility plugin * - * Please refer to {@see PicoPluginApiCompatPluginInterface} for more information about - * how to develop a PicoDeprecated plugin API compatibility plugin. + * Please refer to {@see PluginApiPluginInterface} for more information about how to + * develop a PicoDeprecated plugin API compatibility plugin. * - * @see PicoPluginApiCompatPluginInterface + * @see PluginApiPluginInterface * * @author Daniel Rudolf * @link http://picocms.org * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -abstract class AbstractPicoPluginApiCompatPlugin extends AbstractPicoCompatPlugin implements - PicoPluginApiCompatPluginInterface +abstract class AbstractPluginApiPlugin extends AbstractPlugin implements PluginApiPluginInterface { /** * Map of core events matching event signatures of older API versions * - * @see AbstractPicoPluginApiCompatPlugin::handleEvent() + * @see AbstractPluginApiPlugin::handleEvent() * * @var array */ diff --git a/lib/PicoPluginApiCompatPluginInterface.php b/lib/PluginApiPluginInterface.php similarity index 88% rename from lib/PicoPluginApiCompatPluginInterface.php rename to lib/PluginApiPluginInterface.php index e2e7c1e..0f46557 100644 --- a/lib/PicoPluginApiCompatPluginInterface.php +++ b/lib/PluginApiPluginInterface.php @@ -4,12 +4,14 @@ * in the version control history of the file, available from the following * original location: * - * + * * * SPDX-License-Identifier: MIT * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated; + /** * Common interface for PicoDeprecated plugin API compatibility plugins * @@ -18,7 +20,7 @@ * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -interface PicoPluginApiCompatPluginInterface extends PicoCompatPluginInterface +interface PluginApiPluginInterface extends PluginInterface { /** * Handles custom events for plugins of the supported API version diff --git a/lib/PicoCompatPluginInterface.php b/lib/PluginInterface.php similarity index 92% rename from lib/PicoCompatPluginInterface.php rename to lib/PluginInterface.php index 7492b19..8632a9d 100644 --- a/lib/PicoCompatPluginInterface.php +++ b/lib/PluginInterface.php @@ -4,12 +4,17 @@ * in the version control history of the file, available from the following * original location: * - * + * * * SPDX-License-Identifier: MIT * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated; + +use picocms\Pico\Pico; +use PicoDeprecated; + /** * Common interface for PicoDeprecated compatibility plugins * @@ -18,7 +23,7 @@ * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -interface PicoCompatPluginInterface +interface PluginInterface { /** * Handles a Pico event diff --git a/plugins/PicoMainCompatPlugin.php b/plugins/MainPlugin.php similarity index 91% rename from plugins/PicoMainCompatPlugin.php rename to plugins/MainPlugin.php index 6c84f3c..954bff3 100644 --- a/plugins/PicoMainCompatPlugin.php +++ b/plugins/MainPlugin.php @@ -4,7 +4,7 @@ * in the version control history of the file, available from the following * original location: * - * + * * * This file was created by splitting up an original file into multiple files, * which in turn was previously part of the project's main repository. The @@ -18,6 +18,11 @@ * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated\Plugin; + +use picocms\PicoDeprecated\AbstractPlugin; +use PicoDeprecated; + /** * Maintains backward compatibility with older Pico versions * @@ -26,7 +31,7 @@ * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -class PicoMainCompatPlugin extends AbstractPicoCompatPlugin +class MainPlugin extends AbstractPlugin { /** * Load's config.php from Pico's root and config dir @@ -36,7 +41,7 @@ class PicoMainCompatPlugin extends AbstractPicoCompatPlugin * {@see Pico::loadConfig()}. `onConfigLoaded` is triggered later, thus we * use the `onPluginsLoaded` event. * - * @see PicoMainCompatPlugin::loadScriptedConfig() + * @see MainPlugin::loadScriptedConfig() * * @param object[] $plugins loaded plugin instances */ @@ -62,7 +67,7 @@ public function onPluginsLoaded(array $plugins) * solution. Otherwise we'd have to copy all of Pico's code dealing with * special config settings (like making paths and URLs absolute). * - * @see PicoMainCompatPlugin::onConfigLoaded() + * @see MainPlugin::onConfigLoaded() * @see Pico::loadConfig() * * @param string $configFile path to the config file to load @@ -81,7 +86,7 @@ protected function loadScriptedConfig($configFile) $scriptedConfig = $includeConfigClosure($configFile); if (!empty($scriptedConfig)) { - $picoReflector = new ReflectionObject($this->getPico()); + $picoReflector = new \ReflectionObject($this->getPico()); $picoConfigReflector = $picoReflector->getProperty('config'); $picoConfigReflector->setAccessible(true); diff --git a/plugins/PicoPluginApi0CompatPlugin.php b/plugins/PluginApi0Plugin.php similarity index 92% rename from plugins/PicoPluginApi0CompatPlugin.php rename to plugins/PluginApi0Plugin.php index edf676a..2afa1f0 100644 --- a/plugins/PicoPluginApi0CompatPlugin.php +++ b/plugins/PluginApi0Plugin.php @@ -4,7 +4,7 @@ * in the version control history of the file, available from the following * original location: * - * + * * * This file was created by splitting up an original file into multiple files, * which in turn was previously part of the project's main repository. The @@ -18,6 +18,12 @@ * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated\Plugin; + +use picocms\Pico\Pico; +use picocms\PicoDeprecated\AbstractPluginApiPlugin; +use PicoDeprecated; + /** * Maintains backward compatibility with plugins using API version 0, written * for Pico 0.9 and earlier @@ -27,20 +33,19 @@ * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -class PicoPluginApi0CompatPlugin extends AbstractPicoPluginApiCompatPlugin +class PluginApi0Plugin extends AbstractPluginApiPlugin { /** - * This plugin extends {@see PicoPluginApi1CompatPlugin} and - * {@see PicoThemeApi0CompatPlugin} + * This plugin extends {@see PluginApi1Plugin} and {@see ThemeApi0Plugin} * * @var string[] */ - protected $dependsOn = array('PicoPluginApi1CompatPlugin', 'PicoThemeApi0CompatPlugin'); + protected $dependsOn = array(PluginApi1Plugin::class, ThemeApi0Plugin::class); /** * Map of core events matching event signatures of older API versions * - * @see AbstractPicoPluginApiCompatPlugin::handleEvent() + * @see AbstractPluginApiPlugin::handleEvent() * * @var array */ @@ -60,7 +65,7 @@ class PicoPluginApi0CompatPlugin extends AbstractPicoPluginApiCompatPlugin * Pico's request file * * @see Pico::$requestFile - * @see PicoPluginApi0CompatPlugin::onRequestFile() + * @see PluginApi0Plugin::onRequestFile() * * @var string|null */ @@ -114,7 +119,7 @@ protected function defineConfigConstants(array &$config) define('CONFIG_DIR', $this->getPico()->getConfigDir()); } if (!defined('LIB_DIR')) { - $picoReflector = new ReflectionClass('Pico'); + $picoReflector = new \ReflectionClass(Pico::class); define('LIB_DIR', dirname($picoReflector->getFileName()) . '/'); } if (!defined('PLUGINS_DIR')) { @@ -136,9 +141,9 @@ protected function defineConfigConstants(array &$config) } /** - * Sets PicoPluginApi1CompatPlugin::$requestFile + * Sets PluginApi0Plugin::$requestFile * - * @see PicoPluginApi0CompatPlugin::$requestFile + * @see PluginApi0Plugin::$requestFile * * @param string &$file absolute path to the content file to serve */ @@ -253,11 +258,11 @@ public function onPagesLoaded( * Please note that the `before_render` event gets `$templateName` passed * without its file extension. The file extension is re-added later. * - * @param Twig_Environment &$twig Twig instance + * @param \Twig_Environment &$twig Twig instance * @param string &$templateName file name of the template * @param array &$twigVariables template variables */ - public function onPageRendering(Twig_Environment &$twig, array &$twigVariables, &$templateName) + public function onPageRendering(\Twig_Environment &$twig, array &$twigVariables, &$templateName) { $templateNameInfo = pathinfo($templateName) + array('extension' => ''); diff --git a/plugins/PicoPluginApi1CompatPlugin.php b/plugins/PluginApi1Plugin.php similarity index 85% rename from plugins/PicoPluginApi1CompatPlugin.php rename to plugins/PluginApi1Plugin.php index bc0edd3..f5f7cb2 100644 --- a/plugins/PicoPluginApi1CompatPlugin.php +++ b/plugins/PluginApi1Plugin.php @@ -4,7 +4,7 @@ * in the version control history of the file, available from the following * original location: * - * + * * * This file was created by splitting up an original file into multiple files, * which in turn was previously part of the project's main repository. The @@ -18,6 +18,11 @@ * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated\Plugin; + +use picocms\PicoDeprecated\AbstractPluginApiPlugin; +use PicoDeprecated; + /** * Maintains backward compatibility with plugins using API version 1, written * for Pico 1.0 @@ -27,20 +32,19 @@ * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -class PicoPluginApi1CompatPlugin extends AbstractPicoPluginApiCompatPlugin +class PluginApi1Plugin extends AbstractPluginApiPlugin { /** - * This plugin extends {@see PicoPluginApi2CompatPlugin} and - * {@see PicoThemeApi1CompatPlugin} + * This plugin extends {@see PluginApi2Plugin} and {@see ThemeApi1Plugin} * * @var string[] */ - protected $dependsOn = array('PicoPluginApi2CompatPlugin', 'PicoThemeApi1CompatPlugin'); + protected $dependsOn = array(PluginApi2Plugin::class, ThemeApi1Plugin::class); /** * Map of core events matching event signatures of older API versions * - * @see AbstractPicoPluginApiCompatPlugin::handleEvent() + * @see AbstractPluginApiPlugin::handleEvent() * * @var array */ @@ -61,7 +65,7 @@ class PicoPluginApi1CompatPlugin extends AbstractPicoPluginApiCompatPlugin * Pico's request file * * @see Pico::$requestFile - * @see PicoPluginApi1CompatPlugin::onRequestFile() + * @see PluginApi1Plugin::onRequestFile() * * @var string|null */ @@ -71,7 +75,7 @@ class PicoPluginApi1CompatPlugin extends AbstractPicoPluginApiCompatPlugin * Pico's raw contents * * @see Pico::$rawContent - * @see PicoPluginApi1CompatPlugin::onContentLoaded() + * @see PluginApi1Plugin::onContentLoaded() * * @var string|null */ @@ -81,7 +85,7 @@ class PicoPluginApi1CompatPlugin extends AbstractPicoPluginApiCompatPlugin * Pico's meta headers array * * @see Pico::$metaHeaders - * @see PicoPluginApi1CompatPlugin::onMetaHeaders() + * @see PluginApi1Plugin::onMetaHeaders() * * @var array|null */ @@ -91,7 +95,7 @@ class PicoPluginApi1CompatPlugin extends AbstractPicoPluginApiCompatPlugin * Pico's pages array * * @see Pico::$pages - * @see PicoPluginApi1CompatPlugin::onPagesLoaded() + * @see PluginApi1Plugin::onPagesLoaded() * * @var array[]|null */ @@ -101,9 +105,9 @@ class PicoPluginApi1CompatPlugin extends AbstractPicoPluginApiCompatPlugin * Pico's Twig instance * * @see Pico::$twig - * @see PicoPluginApi1CompatPlugin::onTwigRegistered() + * @see PluginApi1Plugin::onTwigRegistered() * - * @var Twig_Environment|null + * @var \Twig_Environment|null */ protected $twig; @@ -128,7 +132,7 @@ public function onPluginsLoaded(array $plugins) if (!isset($originalPlugins[$pluginName])) { $this->getPico()->loadPlugin($plugin); } elseif ($plugin !== $originalPlugins[$pluginName]) { - throw new RuntimeException( + throw new \RuntimeException( "A Pico plugin using API version 1 tried to replace Pico plugin '" . $pluginName . "' using the " . "onPluginsLoaded() event, however, replacing plugins was removed with API version 2" ); @@ -139,7 +143,7 @@ public function onPluginsLoaded(array $plugins) if ($originalPlugins) { $removedPluginsList = implode("', '", array_keys($originalPlugins)); - throw new RuntimeException( + throw new \RuntimeException( "A Pico plugin using API version 1 tried to unload the Pico plugin(s) '" . $removedPluginsList . "' " . "using the onPluginsLoaded() event, however, unloading plugins was removed with API version 2" ); @@ -147,9 +151,9 @@ public function onPluginsLoaded(array $plugins) } /** - * Sets PicoPluginApi1CompatPlugin::$requestFile + * Sets PluginApi1Plugin::$requestFile * - * @see PicoPluginApi1CompatPlugin::$requestFile + * @see PluginApi1Plugin::$requestFile * * @param string &$file absolute path to the content file to serve */ @@ -167,9 +171,9 @@ public function onContentLoading() } /** - * Sets PicoPluginApi1CompatPlugin::$rawContent + * Sets PluginApi1Plugin::$rawContent * - * @see PicoPluginApi1CompatPlugin::$rawContent + * @see PluginApi1Plugin::$rawContent * * @param string &$rawContent raw file contents */ @@ -189,7 +193,7 @@ public function on404ContentLoading() /** * Triggers the onMetaParsing event * - * @see PicoPluginApi1CompatPlugin::onMetaHeaders() + * @see PluginApi1Plugin::onMetaHeaders() */ public function onMetaParsing() { @@ -218,9 +222,9 @@ public function onContentParsing() } /** - * Sets PicoPluginApi1CompatPlugin::$pages + * Sets PluginApi1Plugin::$pages * - * @see PicoPluginApi1CompatPlugin::$pages + * @see PluginApi1Plugin::$pages * * @param array[] &$pages sorted list of all known pages */ @@ -260,9 +264,9 @@ public function onPageRendering(&$templateName, array &$twigVariables) /** * Triggers the onMetaHeaders event with flipped meta headers and sets - * PicoPluginApi1CompatPlugin::$metaHeaders + * PluginApi1Plugin::$metaHeaders * - * @see PicoPluginApi1CompatPlugin::$metaHeaders + * @see PluginApi1Plugin::$metaHeaders * * @param string[] &$headers list of known meta header fields; the array * key specifies the YAML key to search for, the array value is later @@ -278,13 +282,13 @@ public function onMetaHeaders(array &$headers) } /** - * Sets PicoPluginApi1CompatPlugin::$twig + * Sets PluginApi1Plugin::$twig * - * @see PicoPluginApi1CompatPlugin::$twig + * @see PluginApi1Plugin::$twig * - * @param Twig_Environment &$twig Twig instance + * @param \Twig_Environment &$twig Twig instance */ - public function onTwigRegistered(Twig_Environment &$twig) + public function onTwigRegistered(\Twig_Environment &$twig) { $this->twig = $twig; } @@ -312,7 +316,7 @@ protected function getFlippedMetaHeaders() } /** - * Syncs PicoPluginApi1CompatPlugin::$metaHeaders with a flipped headers array + * Syncs PluginApi1Plugin::$metaHeaders with a flipped headers array * * @param array $headersFlipped flipped headers array */ diff --git a/plugins/PicoPluginApi2CompatPlugin.php b/plugins/PluginApi2Plugin.php similarity index 89% rename from plugins/PicoPluginApi2CompatPlugin.php rename to plugins/PluginApi2Plugin.php index deacf47..e147751 100644 --- a/plugins/PicoPluginApi2CompatPlugin.php +++ b/plugins/PluginApi2Plugin.php @@ -4,7 +4,7 @@ * in the version control history of the file, available from the following * original location: * - * + * * * This file was created by splitting up an original file into multiple files, * which in turn was previously part of the project's main repository. The @@ -18,6 +18,11 @@ * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated\Plugin; + +use picocms\PicoDeprecated\AbstractPluginApiPlugin; +use PicoDeprecated; + /** * Maintains backward compatibility with plugins using API version 2, written * for Pico 2.0 @@ -27,19 +32,19 @@ * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -class PicoPluginApi2CompatPlugin extends AbstractPicoPluginApiCompatPlugin +class PluginApi2Plugin extends AbstractPluginApiPlugin { /** - * This plugin extends {@see PicoThemeApi2CompatPlugin} + * This plugin extends {@see ThemeApi2Plugin} * * @var string[] */ - protected $dependsOn = array('PicoThemeApi2CompatPlugin'); + protected $dependsOn = array(ThemeApi2Plugin::class); /** * Map of core events matching event signatures of older API versions * - * @see AbstractPicoPluginApiCompatPlugin::handleEvent() + * @see AbstractPluginApiPlugin::handleEvent() * * @var array */ @@ -77,17 +82,16 @@ class PicoPluginApi2CompatPlugin extends AbstractPicoPluginApiCompatPlugin * Pico's config array * * @see Pico::$config - * @see PicoPluginApi2CompatPlugin::onConfigLoaded() + * @see PluginApi2Plugin::onConfigLoaded() * * @var array|null */ protected $config; /** - * Sets PicoPluginApi1CompatPlugin::$config and handles the theme_url - * config param + * Sets PluginApi2Plugin::$config and handles the theme_url config param * - * @see PicoPluginApi2CompatPlugin::$config + * @see PluginApi2Plugin::$config * * @param array $config */ diff --git a/plugins/PicoThemeApi0CompatPlugin.php b/plugins/ThemeApi0Plugin.php similarity index 76% rename from plugins/PicoThemeApi0CompatPlugin.php rename to plugins/ThemeApi0Plugin.php index 91d6fdb..07daa43 100644 --- a/plugins/PicoThemeApi0CompatPlugin.php +++ b/plugins/ThemeApi0Plugin.php @@ -4,7 +4,7 @@ * in the version control history of the file, available from the following * original location: * - * + * * * This file was created by splitting up an original file into multiple files, * which in turn was previously part of the project's main repository. The @@ -18,14 +18,19 @@ * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated\Plugin; + +use picocms\PicoDeprecated\AbstractPlugin; +use PicoDeprecated; + /** * Maintains backward compatibility with themes using API version 0, written * for Pico 0.9 and earlier * * Since there were no theme-related changes between Pico 0.9 and Pico 1.0, * this compat plugin doesn't hold any code itself, it just depends on - * {@see PicoThemeApi1CompatPlugin}. Since themes didn't support API versioning - * until Pico 2.1 (i.e. API version 3), all older themes will appear to use API + * {@see ThemeApi1Plugin}. Since themes didn't support API versioning until + * Pico 2.1 (i.e. API version 3), all older themes will appear to use API * version 0. * * @author Daniel Rudolf @@ -33,14 +38,14 @@ * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -class PicoThemeApi0CompatPlugin extends AbstractPicoCompatPlugin +class ThemeApi0Plugin extends AbstractPlugin { /** - * This plugin extends {@see PicoThemeApi1CompatPlugin} + * This plugin extends {@see ThemeApi1Plugin} * * @var string[] */ - protected $dependsOn = array('PicoThemeApi1CompatPlugin'); + protected $dependsOn = array(ThemeApi1Plugin::class); /** * {@inheritDoc} diff --git a/plugins/PicoThemeApi1CompatPlugin.php b/plugins/ThemeApi1Plugin.php similarity index 91% rename from plugins/PicoThemeApi1CompatPlugin.php rename to plugins/ThemeApi1Plugin.php index a7250b9..2594bc5 100644 --- a/plugins/PicoThemeApi1CompatPlugin.php +++ b/plugins/ThemeApi1Plugin.php @@ -4,7 +4,7 @@ * in the version control history of the file, available from the following * original location: * - * + * * * This file was created by splitting up an original file into multiple files, * which in turn was previously part of the project's main repository. The @@ -18,6 +18,11 @@ * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated\Plugin; + +use picocms\PicoDeprecated\AbstractPlugin; +use PicoDeprecated; + /** * Maintains backward compatibility with themes using API version 1, written * for Pico 1.0 @@ -27,19 +32,19 @@ * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -class PicoThemeApi1CompatPlugin extends AbstractPicoCompatPlugin +class ThemeApi1Plugin extends AbstractPlugin { /** - * This plugin extends {@see PicoThemeApi2CompatPlugin} + * This plugin extends {@see ThemeApi2Plugin} * * @var string[] */ - protected $dependsOn = array('PicoThemeApi2CompatPlugin'); + protected $dependsOn = array(ThemeApi2Plugin::class); /** * Lowers the page's meta headers * - * @see PicoThemeApi1CompatPlugin::lowerFileMeta() + * @see ThemeApi1Plugin::lowerFileMeta() * * @param string[] &$meta parsed meta data */ @@ -51,7 +56,7 @@ public function onMetaParsed(array &$meta) /** * Lowers the page's meta headers * - * @see PicoThemeApi1CompatPlugin::lowerFileMeta() + * @see ThemeApi1Plugin::lowerFileMeta() * * @param array &$pageData data of the loaded page */ @@ -93,14 +98,14 @@ public function onPageRendering(&$templateName, array &$twigVariables) try { $twig->loadTemplate($templateName); - } catch (Twig_Error_Loader $e) { + } catch (\Twig_Error_Loader $e) { if ($templateNameInfo['extension'] === 'twig') { try { $twig->loadTemplate($templateNameInfo['filename'] . '.html'); $templateName = $templateNameInfo['filename'] . '.html'; $templateNameInfo['extension'] = 'html'; - } catch (Twig_Error_Loader $e) { + } catch (\Twig_Error_Loader $e) { // template doesn't exist, Twig will very likely fail later } } diff --git a/plugins/PicoThemeApi2CompatPlugin.php b/plugins/ThemeApi2Plugin.php similarity index 88% rename from plugins/PicoThemeApi2CompatPlugin.php rename to plugins/ThemeApi2Plugin.php index 9d8bd73..e7154cb 100644 --- a/plugins/PicoThemeApi2CompatPlugin.php +++ b/plugins/ThemeApi2Plugin.php @@ -4,7 +4,7 @@ * in the version control history of the file, available from the following * original location: * - * + * * * This file was created by splitting up an original file into multiple files, * which in turn was previously part of the project's main repository. The @@ -18,6 +18,11 @@ * License-Filename: LICENSE */ +namespace picocms\PicoDeprecated\Plugin; + +use picocms\PicoDeprecated\AbstractPlugin; +use PicoDeprecated; + /** * Maintains backward compatibility with themes using API version 2, written * for Pico 2.0 @@ -27,7 +32,7 @@ * @license http://opensource.org/licenses/MIT The MIT License * @version 3.0 */ -class PicoThemeApi2CompatPlugin extends AbstractPicoCompatPlugin +class ThemeApi2Plugin extends AbstractPlugin { /** * Manually configured Twig escape strategy @@ -44,9 +49,9 @@ class PicoThemeApi2CompatPlugin extends AbstractPicoCompatPlugin protected $pluginPaths = array(); /** - * Sets PicoThemeApi2CompatPlugin::$twigEscapeStrategy + * Sets ThemeApi2Plugin::$twigEscapeStrategy * - * @see PicoThemeApi2CompatPlugin::$twigEscapeStrategy + * @see ThemeApi2Plugin::$twigEscapeStrategy * * @param array &$config array of config variables */ @@ -71,17 +76,17 @@ public function onPageRendering(&$templateName, array &$twigVariables) } /** - * Registers PicoPluginApi2CompatPlugin::twigEscapeStrategy() as Twig's - * default escape strategy + * Registers PluginApi2Plugin::twigEscapeStrategy() as Twig's default + * escape strategy * - * @see PicoPluginApi2CompatPlugin::twigEscapeStrategy() + * @see PluginApi2Plugin::twigEscapeStrategy() * - * @param Twig_Environment &$twig Twig instance + * @param \Twig_Environment &$twig Twig instance */ - public function onTwigRegistered(Twig_Environment &$twig) + public function onTwigRegistered(\Twig_Environment &$twig) { if ($twig->hasExtension('Twig_Extension_Escaper')) { - /** @var Twig_Extension_Escaper $escaperExtension */ + /** @var \Twig_Extension_Escaper $escaperExtension */ $escaperExtension = $twig->getExtension('Twig_Extension_Escaper'); $escaperExtension->setDefaultStrategy(array($this, 'twigEscapeStrategy')); } @@ -118,10 +123,10 @@ public function twigEscapeStrategy($templateName) return false; } - /** @var Twig_SourceContextLoaderInterface $twigLoader */ + /** @var \Twig_SourceContextLoaderInterface $twigLoader */ $twigLoader = $this->getPico()->getTwig()->getLoader(); - if (!$twigLoader instanceof Twig_SourceContextLoaderInterface) { - throw new RuntimeException( + if (!$twigLoader instanceof \Twig_SourceContextLoaderInterface) { + throw new \RuntimeException( "PicoDeprecated compat plugin '" . __CLASS__ . "' requires a 'Twig_SourceContextLoaderInterface' " . "Twig loader, '" . get_class($twigLoader) . "' given" ); @@ -178,7 +183,7 @@ protected function getPluginFromPath($path) continue; } - $pluginReflector = new ReflectionObject($plugin); + $pluginReflector = new \ReflectionObject($plugin); $pluginPath = dirname($pluginReflector->getFileName() ?: '') . '/'; if (in_array($pluginPath, array('/', $rootDir, $vendorDir, $pluginsDir, $themesDir), true)) { From 3c12ea4bd8e4f4e12242a17593018fef78158d63 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sat, 11 Apr 2020 20:58:57 +0200 Subject: [PATCH 06/28] Update code styling to PHP 7.0+ --- PicoDeprecated.php | 28 +++++++-------- lib/AbstractPlugin.php | 4 +-- lib/AbstractPluginApiPlugin.php | 6 ++-- lib/PluginApiPluginInterface.php | 2 +- plugins/MainPlugin.php | 4 +-- plugins/PluginApi0Plugin.php | 48 ++++++++++++------------- plugins/PluginApi1Plugin.php | 46 ++++++++++++------------ plugins/PluginApi2Plugin.php | 62 ++++++++++++++++---------------- plugins/ThemeApi0Plugin.php | 2 +- plugins/ThemeApi1Plugin.php | 6 ++-- plugins/ThemeApi2Plugin.php | 6 ++-- 11 files changed, 107 insertions(+), 107 deletions(-) diff --git a/PicoDeprecated.php b/PicoDeprecated.php index 3248cd0..6be6fe2 100644 --- a/PicoDeprecated.php +++ b/PicoDeprecated.php @@ -49,35 +49,35 @@ class PicoDeprecated extends AbstractPicoPlugin * * @var int */ - const API_VERSION = 3; + public const API_VERSION = 3; /** * API version 0, used by Pico 0.9 and earlier * * @var int */ - const API_VERSION_0 = 0; + public const API_VERSION_0 = 0; /** * API version 1, used by Pico 1.0 * * @var int */ - const API_VERSION_1 = 1; + public const API_VERSION_1 = 1; /** * API version 2, used by Pico 2.0 * * @var int */ - const API_VERSION_2 = 2; + public const API_VERSION_2 = 2; /** * API version 3, used by Pico 2.1 * * @var int */ - const API_VERSION_3 = 3; + public const API_VERSION_3 = 3; /** * Loaded plugins, indexed by API version @@ -86,7 +86,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @var object[] */ - protected $plugins = array(); + protected $plugins = []; /** * Loaded compatibility plugins @@ -95,7 +95,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @var PluginInterface[] */ - protected $compatPlugins = array(); + protected $compatPlugins = []; /** * {@inheritDoc} @@ -163,7 +163,7 @@ public function onPluginsLoaded(array $plugins) $this->loadPlugin($plugin); } - $this->getPico()->triggerEvent('onPicoDeprecated', array($this)); + $this->getPico()->triggerEvent('onPicoDeprecated', [ $this ]); } /** @@ -206,7 +206,7 @@ protected function loadPlugin($plugin) $apiVersion = $this->getPluginApiVersion($plugin); if (!isset($this->plugins[$apiVersion])) { - $this->plugins[$apiVersion] = array(); + $this->plugins[$apiVersion] = []; $this->loadPluginApiCompatPlugin($apiVersion); } @@ -222,7 +222,7 @@ protected function loadPlugin($plugin) */ public function getPlugins($apiVersion) { - return isset($this->plugins[$apiVersion]) ? $this->plugins[$apiVersion] : array(); + return isset($this->plugins[$apiVersion]) ? $this->plugins[$apiVersion] : []; } /** @@ -320,7 +320,7 @@ public function getCompatPlugins() * @param string $eventName event to trigger * @param array $params optional parameters to pass */ - public function triggerEvent($apiVersion, $eventName, array $params = array()) + public function triggerEvent($apiVersion, $eventName, array $params = []) { foreach ($this->getPlugins($apiVersion) as $plugin) { $plugin->handleEvent($eventName, $params); @@ -354,7 +354,7 @@ public function getPluginApiVersion($plugin) */ public function getCoreEvents() { - return array( + return [ 'onPluginsLoaded', 'onPluginManuallyLoaded', 'onConfigLoaded', @@ -384,7 +384,7 @@ public function getCoreEvents() 'onMetaHeaders', 'onYamlParserRegistered', 'onParsedownRegistered', - 'onTwigRegistered' - ); + 'onTwigRegistered', + ]; } } diff --git a/lib/AbstractPlugin.php b/lib/AbstractPlugin.php index 0daf79a..590ccef 100644 --- a/lib/AbstractPlugin.php +++ b/lib/AbstractPlugin.php @@ -56,7 +56,7 @@ abstract class AbstractPlugin implements PluginInterface * * @var string[] */ - protected $dependsOn = array(); + protected $dependsOn = []; /** * Constructs a new instance of a PicoDeprecated compatibility plugin @@ -76,7 +76,7 @@ public function __construct(Pico $pico, PicoDeprecated $picoDeprecated) public function handleEvent($eventName, array $params) { if (method_exists($this, $eventName)) { - call_user_func_array(array($this, $eventName), $params); + call_user_func_array([ $this, $eventName ], $params); } } diff --git a/lib/AbstractPluginApiPlugin.php b/lib/AbstractPluginApiPlugin.php index 3b85696..c6a2c0a 100644 --- a/lib/AbstractPluginApiPlugin.php +++ b/lib/AbstractPluginApiPlugin.php @@ -35,7 +35,7 @@ abstract class AbstractPluginApiPlugin extends AbstractPlugin implements PluginA * * @var array */ - protected $eventAliases = array(); + protected $eventAliases = []; /** * {@inheritDoc} @@ -55,7 +55,7 @@ public function handleEvent($eventName, array $params) /** * {@inheritDoc} */ - public function handleCustomEvent($eventName, array $params = array()) + public function handleCustomEvent($eventName, array $params = []) { $this->getPicoDeprecated()->triggerEvent($this->getApiVersionSupport(), $eventName, $params); } @@ -66,7 +66,7 @@ public function handleCustomEvent($eventName, array $params = array()) * @param string $eventName name of the event to trigger * @param array $params optional parameters to pass */ - protected function triggerEvent($eventName, array $params = array()) + protected function triggerEvent($eventName, array $params = []) { $apiVersion = $this->getApiVersionSupport(); $picoDeprecated = $this->getPicoDeprecated(); diff --git a/lib/PluginApiPluginInterface.php b/lib/PluginApiPluginInterface.php index 0f46557..f2bde14 100644 --- a/lib/PluginApiPluginInterface.php +++ b/lib/PluginApiPluginInterface.php @@ -28,7 +28,7 @@ interface PluginApiPluginInterface extends PluginInterface * @param string $eventName name of the triggered event * @param array $params passed parameters */ - public function handleCustomEvent($eventName, array $params = array()); + public function handleCustomEvent($eventName, array $params = []); /** * Returns the API version this plugin maintains backward compatibility for diff --git a/plugins/MainPlugin.php b/plugins/MainPlugin.php index 954bff3..c5fb93b 100644 --- a/plugins/MainPlugin.php +++ b/plugins/MainPlugin.php @@ -77,7 +77,7 @@ protected function loadScriptedConfig($configFile) // scope isolated require() $includeConfigClosure = function ($configFile) { require($configFile); - return (isset($config) && is_array($config)) ? $config : array(); + return (isset($config) && is_array($config)) ? $config : []; }; if (PHP_VERSION_ID >= 50400) { $includeConfigClosure = $includeConfigClosure->bindTo(null); @@ -90,7 +90,7 @@ protected function loadScriptedConfig($configFile) $picoConfigReflector = $picoReflector->getProperty('config'); $picoConfigReflector->setAccessible(true); - $config = $picoConfigReflector->getValue($this->getPico()) ?: array(); + $config = $picoConfigReflector->getValue($this->getPico()) ?: []; $config += $scriptedConfig; $picoConfigReflector->setValue($this->getPico(), $config); diff --git a/plugins/PluginApi0Plugin.php b/plugins/PluginApi0Plugin.php index 2afa1f0..6de3bd7 100644 --- a/plugins/PluginApi0Plugin.php +++ b/plugins/PluginApi0Plugin.php @@ -40,7 +40,7 @@ class PluginApi0Plugin extends AbstractPluginApiPlugin * * @var string[] */ - protected $dependsOn = array(PluginApi1Plugin::class, ThemeApi0Plugin::class); + protected $dependsOn = [ PluginApi1Plugin::class, ThemeApi0Plugin::class ]; /** * Map of core events matching event signatures of older API versions @@ -49,17 +49,17 @@ class PluginApi0Plugin extends AbstractPluginApiPlugin * * @var array */ - protected $eventAliases = array( - 'onConfigLoaded' => array('config_loaded'), - 'onRequestUrl' => array('request_url'), - 'onContentLoading' => array('before_load_content'), - 'on404ContentLoading' => array('before_404_load_content'), - 'onMetaParsed' => array('file_meta'), - 'onContentParsing' => array('before_parse_content'), - 'onContentParsed' => array('after_parse_content', 'content_parsed'), - 'onTwigRegistration' => array('before_twig_register'), - 'onPageRendered' => array('after_render') - ); + protected $eventAliases = [ + 'onConfigLoaded' => [ 'config_loaded' ], + 'onRequestUrl' => [ 'request_url' ], + 'onContentLoading' => [ 'before_load_content' ], + 'on404ContentLoading' => [ 'before_404_load_content' ], + 'onMetaParsed' => [ 'file_meta' ], + 'onContentParsing' => [ 'before_parse_content' ], + 'onContentParsed' => [ 'after_parse_content', 'content_parsed' ], + 'onTwigRegistration' => [ 'before_twig_register' ], + 'onPageRendered' => [ 'after_render' ], + ]; /** * Pico's request file @@ -159,7 +159,7 @@ public function onRequestFile(&$file) */ public function on404ContentLoaded(&$rawContent) { - $this->triggerEvent('after_404_load_content', array(&$this->requestFile, &$rawContent)); + $this->triggerEvent('after_404_load_content', [ &$this->requestFile, &$rawContent ]); } /** @@ -169,7 +169,7 @@ public function on404ContentLoaded(&$rawContent) */ public function onContentLoaded(&$rawContent) { - $this->triggerEvent('after_load_content', array(&$this->requestFile, &$rawContent)); + $this->triggerEvent('after_load_content', [ &$this->requestFile, &$rawContent ]); } /** @@ -180,7 +180,7 @@ public function onContentLoaded(&$rawContent) */ public function onMetaParsing(&$rawContent, array &$headers) { - $this->triggerEvent('before_read_file_meta', array(&$headers)); + $this->triggerEvent('before_read_file_meta', [ &$headers ]); } /** @@ -190,7 +190,7 @@ public function onMetaParsing(&$rawContent, array &$headers) */ public function onSinglePageLoaded(array &$pageData) { - $this->triggerEvent('get_page_data', array(&$pageData, $pageData['meta'])); + $this->triggerEvent('get_page_data', [ &$pageData, $pageData['meta'] ]); } /** @@ -214,20 +214,20 @@ public function onPagesLoaded( array &$nextPage = null ) { // remove keys of pages array - $plainPages = array(); + $plainPages = []; foreach ($pages as &$plainPageData) { $plainPages[] = &$plainPageData; } // trigger event - $this->triggerEvent('get_pages', array(&$plainPages, &$currentPage, &$previousPage, &$nextPage)); + $this->triggerEvent('get_pages', [ &$plainPages, &$currentPage, &$previousPage, &$nextPage ]); // re-index pages array $baseUrl = $this->getPico()->getBaseUrl(); $baseUrlLength = strlen($baseUrl); $urlRewritingEnabled = $this->getPico()->isUrlRewritingEnabled(); - $pages = array(); + $pages = []; foreach ($plainPages as &$pageData) { if (!isset($pageData['id'])) { if (substr($pageData['url'], 0, $baseUrlLength) === $baseUrl) { @@ -264,12 +264,12 @@ public function onPagesLoaded( */ public function onPageRendering(\Twig_Environment &$twig, array &$twigVariables, &$templateName) { - $templateNameInfo = pathinfo($templateName) + array('extension' => ''); + $templateNameInfo = pathinfo($templateName) + [ 'extension' => '' ]; // the template name hasn't had a file extension in API v0 $templateName = $templateNameInfo['filename']; - $this->triggerEvent('before_render', array(&$twigVariables, &$twig, &$templateName)); + $this->triggerEvent('before_render', [ &$twigVariables, &$twig, &$templateName ]); // recover original file extension // we assume that all templates of a theme use the same file extension @@ -279,7 +279,7 @@ public function onPageRendering(\Twig_Environment &$twig, array &$twigVariables, /** * {@inheritDoc} */ - public function handleCustomEvent($eventName, array $params = array()) + public function handleCustomEvent($eventName, array $params = []) { // never trigger custom events } @@ -287,7 +287,7 @@ public function handleCustomEvent($eventName, array $params = array()) /** * {@inheritDoc} */ - public function triggerEvent($eventName, array $params = array()) + public function triggerEvent($eventName, array $params = []) { // we don't support compat plugins using API v0, so no need to take care of compat plugins here // API v0 events are also triggered on plugins using API v1 (but not later) @@ -296,7 +296,7 @@ public function triggerEvent($eventName, array $params = array()) foreach ($plugins as $plugin) { if (method_exists($plugin, $eventName)) { - call_user_func_array(array($plugin, $eventName), $params); + call_user_func_array([ $plugin, $eventName ], $params); } } } diff --git a/plugins/PluginApi1Plugin.php b/plugins/PluginApi1Plugin.php index f5f7cb2..c78c89d 100644 --- a/plugins/PluginApi1Plugin.php +++ b/plugins/PluginApi1Plugin.php @@ -39,7 +39,7 @@ class PluginApi1Plugin extends AbstractPluginApiPlugin * * @var string[] */ - protected $dependsOn = array(PluginApi2Plugin::class, ThemeApi1Plugin::class); + protected $dependsOn = [ PluginApi2Plugin::class, ThemeApi1Plugin::class ]; /** * Map of core events matching event signatures of older API versions @@ -48,18 +48,18 @@ class PluginApi1Plugin extends AbstractPluginApiPlugin * * @var array */ - protected $eventAliases = array( - 'onConfigLoaded' => array('onConfigLoaded'), - 'onRequestUrl' => array('onRequestUrl'), - 'onRequestFile' => array('onRequestFile'), - 'on404ContentLoaded' => array('on404ContentLoaded'), - 'onContentLoaded' => array('onContentLoaded'), - 'onContentPrepared' => array('onContentPrepared'), - 'onContentParsed' => array('onContentParsed'), - 'onPagesLoading' => array('onPagesLoading'), - 'onSinglePageLoaded' => array('onSinglePageLoaded'), - 'onPageRendered' => array('onPageRendered') - ); + protected $eventAliases = [ + 'onConfigLoaded' => [ 'onConfigLoaded' ], + 'onRequestUrl' => [ 'onRequestUrl' ], + 'onRequestFile' => [ 'onRequestFile' ], + 'on404ContentLoaded' => [ 'on404ContentLoaded' ], + 'onContentLoaded' => [ 'onContentLoaded' ], + 'onContentPrepared' => [ 'onContentPrepared' ], + 'onContentParsed' => [ 'onContentParsed' ], + 'onPagesLoading' => [ 'onPagesLoading' ], + 'onSinglePageLoaded' => [ 'onSinglePageLoaded' ], + 'onPageRendered' => [ 'onPageRendered' ], + ]; /** * Pico's request file @@ -126,7 +126,7 @@ public function onPluginsLoaded(array $plugins) { $originalPlugins = $plugins; - $this->triggerEvent('onPluginsLoaded', array(&$plugins)); + $this->triggerEvent('onPluginsLoaded', [ &$plugins ]); foreach ($plugins as $pluginName => $plugin) { if (!isset($originalPlugins[$pluginName])) { @@ -167,7 +167,7 @@ public function onRequestFile(&$file) */ public function onContentLoading() { - $this->triggerEvent('onContentLoading', array(&$this->requestFile)); + $this->triggerEvent('onContentLoading', [ &$this->requestFile ]); } /** @@ -187,7 +187,7 @@ public function onContentLoaded(&$rawContent) */ public function on404ContentLoading() { - $this->triggerEvent('on404ContentLoading', array(&$this->requestFile)); + $this->triggerEvent('on404ContentLoading', [ &$this->requestFile ]); } /** @@ -198,7 +198,7 @@ public function on404ContentLoading() public function onMetaParsing() { $headersFlipped = $this->getFlippedMetaHeaders(); - $this->triggerEvent('onMetaParsing', array(&$this->rawContent, &$headersFlipped)); + $this->triggerEvent('onMetaParsing', [ &$this->rawContent, &$headersFlipped ]); $this->updateFlippedMetaHeaders($headersFlipped); } @@ -209,7 +209,7 @@ public function onMetaParsing() */ public function onMetaParsed(array &$meta) { - $this->triggerEvent('onMetaParsed', array(&$meta)); + $this->triggerEvent('onMetaParsed', [ &$meta ]); $this->triggerEvent('onParsedownRegistration'); } @@ -218,7 +218,7 @@ public function onMetaParsed(array &$meta) */ public function onContentParsing() { - $this->triggerEvent('onContentParsing', array(&$this->rawContent)); + $this->triggerEvent('onContentParsing', [ &$this->rawContent ]); } /** @@ -245,7 +245,7 @@ public function onCurrentPageDiscovered( array &$previousPage = null, array &$nextPage = null ) { - $this->triggerEvent('onPagesLoaded', array(&$this->pages, &$currentPage, &$previousPage, &$nextPage)); + $this->triggerEvent('onPagesLoaded', [ &$this->pages, &$currentPage, &$previousPage, &$nextPage ]); $this->triggerEvent('onTwigRegistration'); $this->getPico()->getTwig(); @@ -259,7 +259,7 @@ public function onCurrentPageDiscovered( */ public function onPageRendering(&$templateName, array &$twigVariables) { - $this->triggerEvent('onPageRendering', array(&$this->twig, &$twigVariables, &$templateName)); + $this->triggerEvent('onPageRendering', [ &$this->twig, &$twigVariables, &$templateName ]); } /** @@ -277,7 +277,7 @@ public function onMetaHeaders(array &$headers) $this->metaHeaders = &$headers; $headersFlipped = $this->getFlippedMetaHeaders(); - $this->triggerEvent('onMetaHeaders', array(&$headersFlipped)); + $this->triggerEvent('onMetaHeaders', [ &$headersFlipped ]); $this->updateFlippedMetaHeaders($headersFlipped); } @@ -312,7 +312,7 @@ protected function getFlippedMetaHeaders() $this->getPico()->getMetaHeaders(); } - return array_flip($this->metaHeaders ?: array()); + return array_flip($this->metaHeaders ?: []); } /** diff --git a/plugins/PluginApi2Plugin.php b/plugins/PluginApi2Plugin.php index e147751..6cb9b70 100644 --- a/plugins/PluginApi2Plugin.php +++ b/plugins/PluginApi2Plugin.php @@ -39,7 +39,7 @@ class PluginApi2Plugin extends AbstractPluginApiPlugin * * @var string[] */ - protected $dependsOn = array(ThemeApi2Plugin::class); + protected $dependsOn = [ ThemeApi2Plugin::class ]; /** * Map of core events matching event signatures of older API versions @@ -48,35 +48,35 @@ class PluginApi2Plugin extends AbstractPluginApiPlugin * * @var array */ - protected $eventAliases = array( - 'onPluginsLoaded' => array('onPluginsLoaded'), - 'onPluginManuallyLoaded' => array('onPluginManuallyLoaded'), - 'onRequestUrl' => array('onRequestUrl'), - 'onRequestFile' => array('onRequestFile'), - 'onContentLoading' => array('onContentLoading'), - 'on404ContentLoading' => array('on404ContentLoading'), - 'on404ContentLoaded' => array('on404ContentLoaded'), - 'onContentLoaded' => array('onContentLoaded'), - 'onMetaParsing' => array('onMetaParsing'), - 'onMetaParsed' => array('onMetaParsed'), - 'onContentParsing' => array('onContentParsing'), - 'onContentPrepared' => array('onContentPrepared'), - 'onContentParsed' => array('onContentParsed'), - 'onPagesLoading' => array('onPagesLoading'), - 'onSinglePageLoading' => array('onSinglePageLoading'), - 'onSinglePageContent' => array('onSinglePageContent'), - 'onSinglePageLoaded' => array('onSinglePageLoaded'), - 'onPagesDiscovered' => array('onPagesDiscovered'), - 'onPagesLoaded' => array('onPagesLoaded'), - 'onCurrentPageDiscovered' => array('onCurrentPageDiscovered'), - 'onPageTreeBuilt' => array('onPageTreeBuilt'), - 'onPageRendering' => array('onPageRendering'), - 'onPageRendered' => array('onPageRendered'), - 'onMetaHeaders' => array('onMetaHeaders'), - 'onYamlParserRegistered' => array('onYamlParserRegistered'), - 'onParsedownRegistered' => array('onParsedownRegistered'), - 'onTwigRegistered' => array('onTwigRegistered') - ); + protected $eventAliases = [ + 'onPluginsLoaded' => [ 'onPluginsLoaded' ], + 'onPluginManuallyLoaded' => [ 'onPluginManuallyLoaded' ], + 'onRequestUrl' => [ 'onRequestUrl' ], + 'onRequestFile' => [ 'onRequestFile' ], + 'onContentLoading' => [ 'onContentLoading' ], + 'on404ContentLoading' => [ 'on404ContentLoading' ], + 'on404ContentLoaded' => [ 'on404ContentLoaded' ], + 'onContentLoaded' => [ 'onContentLoaded' ], + 'onMetaParsing' => [ 'onMetaParsing' ], + 'onMetaParsed' => [ 'onMetaParsed' ], + 'onContentParsing' => [ 'onContentParsing' ], + 'onContentPrepared' => [ 'onContentPrepared' ], + 'onContentParsed' => [ 'onContentParsed' ], + 'onPagesLoading' => [ 'onPagesLoading' ], + 'onSinglePageLoading' => [ 'onSinglePageLoading' ], + 'onSinglePageContent' => [ 'onSinglePageContent' ], + 'onSinglePageLoaded' => [ 'onSinglePageLoaded' ], + 'onPagesDiscovered' => [ 'onPagesDiscovered' ], + 'onPagesLoaded' => [ 'onPagesLoaded' ], + 'onCurrentPageDiscovered' => [ 'onCurrentPageDiscovered' ], + 'onPageTreeBuilt' => [ 'onPageTreeBuilt' ], + 'onPageRendering' => [ 'onPageRendering' ], + 'onPageRendered' => [ 'onPageRendered' ], + 'onMetaHeaders' => [ 'onMetaHeaders' ], + 'onYamlParserRegistered' => [ 'onYamlParserRegistered' ], + 'onParsedownRegistered' => [ 'onParsedownRegistered' ], + 'onTwigRegistered' => [ 'onTwigRegistered' ], + ]; /** * Pico's config array @@ -114,7 +114,7 @@ public function onConfigLoaded(array &$config) */ public function onThemeLoaded($theme, $themeApiVersion, array &$themeConfig) { - $this->triggerEvent('onConfigLoaded', array(&$this->config)); + $this->triggerEvent('onConfigLoaded', [ &$this->config ]); } /** diff --git a/plugins/ThemeApi0Plugin.php b/plugins/ThemeApi0Plugin.php index 07daa43..c93bf1f 100644 --- a/plugins/ThemeApi0Plugin.php +++ b/plugins/ThemeApi0Plugin.php @@ -45,7 +45,7 @@ class ThemeApi0Plugin extends AbstractPlugin * * @var string[] */ - protected $dependsOn = array(ThemeApi1Plugin::class); + protected $dependsOn = [ ThemeApi1Plugin::class ]; /** * {@inheritDoc} diff --git a/plugins/ThemeApi1Plugin.php b/plugins/ThemeApi1Plugin.php index 2594bc5..bee2475 100644 --- a/plugins/ThemeApi1Plugin.php +++ b/plugins/ThemeApi1Plugin.php @@ -39,7 +39,7 @@ class ThemeApi1Plugin extends AbstractPlugin * * @var string[] */ - protected $dependsOn = array(ThemeApi2Plugin::class); + protected $dependsOn = [ ThemeApi2Plugin::class ]; /** * Lowers the page's meta headers @@ -93,7 +93,7 @@ public function onPageRendering(&$templateName, array &$twigVariables) // API v2 requires themes to use .twig as file extension // try to load the template and if this fails, try .html instead (as of API v1) - $templateNameInfo = pathinfo($templateName) + array('extension' => ''); + $templateNameInfo = pathinfo($templateName) + [ 'extension' => '' ]; $twig = $this->getPico()->getTwig(); try { @@ -125,7 +125,7 @@ protected function lowerFileMeta(array &$meta) $metaHeaders = $this->getPico()->getMetaHeaders(); // get unregistered meta - $unregisteredMeta = array(); + $unregisteredMeta = []; foreach ($meta as $key => $value) { if (!in_array($key, $metaHeaders)) { $unregisteredMeta[$key] = &$meta[$key]; diff --git a/plugins/ThemeApi2Plugin.php b/plugins/ThemeApi2Plugin.php index e7154cb..1001e1a 100644 --- a/plugins/ThemeApi2Plugin.php +++ b/plugins/ThemeApi2Plugin.php @@ -46,7 +46,7 @@ class ThemeApi2Plugin extends AbstractPlugin * * @var string[] */ - protected $pluginPaths = array(); + protected $pluginPaths = []; /** * Sets ThemeApi2Plugin::$twigEscapeStrategy @@ -88,7 +88,7 @@ public function onTwigRegistered(\Twig_Environment &$twig) if ($twig->hasExtension('Twig_Extension_Escaper')) { /** @var \Twig_Extension_Escaper $escaperExtension */ $escaperExtension = $twig->getExtension('Twig_Extension_Escaper'); - $escaperExtension->setDefaultStrategy(array($this, 'twigEscapeStrategy')); + $escaperExtension->setDefaultStrategy([ $this, 'twigEscapeStrategy' ]); } } @@ -186,7 +186,7 @@ protected function getPluginFromPath($path) $pluginReflector = new \ReflectionObject($plugin); $pluginPath = dirname($pluginReflector->getFileName() ?: '') . '/'; - if (in_array($pluginPath, array('/', $rootDir, $vendorDir, $pluginsDir, $themesDir), true)) { + if (in_array($pluginPath, [ '/', $rootDir, $vendorDir, $pluginsDir, $themesDir ], true)) { $pluginPath = ''; } From f1e1fefd93ce291a44c20192c191b7c2e0895eb3 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sat, 11 Apr 2020 21:13:04 +0200 Subject: [PATCH 07/28] Update to Symfony YAML 5.0 and Twig 3.0 --- composer.json | 2 +- plugins/PluginApi0Plugin.php | 9 +++++---- plugins/PluginApi1Plugin.php | 7 ++++--- plugins/ThemeApi1Plugin.php | 5 +++-- plugins/ThemeApi2Plugin.php | 24 +++++++++++------------- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index ee88390..ee4adbe 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "source": "https://github.com/picocms/pico-deprecated" }, "require": { - "php": ">=7.0.0", + "php": ">=7.2.5", "picocms/pico": "self.version" }, "autoload": { diff --git a/plugins/PluginApi0Plugin.php b/plugins/PluginApi0Plugin.php index 6de3bd7..d9a40ec 100644 --- a/plugins/PluginApi0Plugin.php +++ b/plugins/PluginApi0Plugin.php @@ -23,6 +23,7 @@ use picocms\Pico\Pico; use picocms\PicoDeprecated\AbstractPluginApiPlugin; use PicoDeprecated; +use Twig\Environment as TwigEnvironment; /** * Maintains backward compatibility with plugins using API version 0, written @@ -258,11 +259,11 @@ public function onPagesLoaded( * Please note that the `before_render` event gets `$templateName` passed * without its file extension. The file extension is re-added later. * - * @param \Twig_Environment &$twig Twig instance - * @param string &$templateName file name of the template - * @param array &$twigVariables template variables + * @param TwigEnvironment &$twig Twig instance + * @param string &$templateName file name of the template + * @param array &$twigVariables template variables */ - public function onPageRendering(\Twig_Environment &$twig, array &$twigVariables, &$templateName) + public function onPageRendering(TwigEnvironment &$twig, array &$twigVariables, &$templateName) { $templateNameInfo = pathinfo($templateName) + [ 'extension' => '' ]; diff --git a/plugins/PluginApi1Plugin.php b/plugins/PluginApi1Plugin.php index c78c89d..9bf624e 100644 --- a/plugins/PluginApi1Plugin.php +++ b/plugins/PluginApi1Plugin.php @@ -22,6 +22,7 @@ use picocms\PicoDeprecated\AbstractPluginApiPlugin; use PicoDeprecated; +use Twig\Environment as TwigEnvironment; /** * Maintains backward compatibility with plugins using API version 1, written @@ -107,7 +108,7 @@ class PluginApi1Plugin extends AbstractPluginApiPlugin * @see Pico::$twig * @see PluginApi1Plugin::onTwigRegistered() * - * @var \Twig_Environment|null + * @var TwigEnvironment|null */ protected $twig; @@ -286,9 +287,9 @@ public function onMetaHeaders(array &$headers) * * @see PluginApi1Plugin::$twig * - * @param \Twig_Environment &$twig Twig instance + * @param TwigEnvironment &$twig Twig instance */ - public function onTwigRegistered(\Twig_Environment &$twig) + public function onTwigRegistered(TwigEnvironment &$twig) { $this->twig = $twig; } diff --git a/plugins/ThemeApi1Plugin.php b/plugins/ThemeApi1Plugin.php index bee2475..6d62770 100644 --- a/plugins/ThemeApi1Plugin.php +++ b/plugins/ThemeApi1Plugin.php @@ -22,6 +22,7 @@ use picocms\PicoDeprecated\AbstractPlugin; use PicoDeprecated; +use Twig\Error\LoaderError as TwigLoaderError; /** * Maintains backward compatibility with themes using API version 1, written @@ -98,14 +99,14 @@ public function onPageRendering(&$templateName, array &$twigVariables) try { $twig->loadTemplate($templateName); - } catch (\Twig_Error_Loader $e) { + } catch (TwigLoaderError $e) { if ($templateNameInfo['extension'] === 'twig') { try { $twig->loadTemplate($templateNameInfo['filename'] . '.html'); $templateName = $templateNameInfo['filename'] . '.html'; $templateNameInfo['extension'] = 'html'; - } catch (\Twig_Error_Loader $e) { + } catch (TwigLoaderError $e) { // template doesn't exist, Twig will very likely fail later } } diff --git a/plugins/ThemeApi2Plugin.php b/plugins/ThemeApi2Plugin.php index 1001e1a..bcdb9f8 100644 --- a/plugins/ThemeApi2Plugin.php +++ b/plugins/ThemeApi2Plugin.php @@ -22,6 +22,10 @@ use picocms\PicoDeprecated\AbstractPlugin; use PicoDeprecated; +use Twig\Environment as TwigEnvironment; +use Twig\Error\LoaderError as TwigLoaderError; +use Twig\Extension\EscaperExtension as TwigEscaperExtension; +use Twig\Loader\LoaderInterface as TwigLoaderInterface; /** * Maintains backward compatibility with themes using API version 2, written @@ -81,13 +85,13 @@ public function onPageRendering(&$templateName, array &$twigVariables) * * @see PluginApi2Plugin::twigEscapeStrategy() * - * @param \Twig_Environment &$twig Twig instance + * @param TwigEnvironment &$twig Twig instance */ - public function onTwigRegistered(\Twig_Environment &$twig) + public function onTwigRegistered(TwigEnvironment &$twig) { - if ($twig->hasExtension('Twig_Extension_Escaper')) { - /** @var \Twig_Extension_Escaper $escaperExtension */ - $escaperExtension = $twig->getExtension('Twig_Extension_Escaper'); + if ($twig->hasExtension(TwigEscaperExtension::class)) { + /** @var TwigEscaperExtension $escaperExtension */ + $escaperExtension = $twig->getExtension(TwigEscaperExtension::class); $escaperExtension->setDefaultStrategy([ $this, 'twigEscapeStrategy' ]); } } @@ -123,18 +127,12 @@ public function twigEscapeStrategy($templateName) return false; } - /** @var \Twig_SourceContextLoaderInterface $twigLoader */ + /** @var TwigLoaderInterface $twigLoader */ $twigLoader = $this->getPico()->getTwig()->getLoader(); - if (!$twigLoader instanceof \Twig_SourceContextLoaderInterface) { - throw new \RuntimeException( - "PicoDeprecated compat plugin '" . __CLASS__ . "' requires a 'Twig_SourceContextLoaderInterface' " - . "Twig loader, '" . get_class($twigLoader) . "' given" - ); - } try { $templatePath = $twigLoader->getSourceContext($templateName)->getPath(); - } catch (\Twig\Error\LoaderError $e) { + } catch (TwigLoaderError $e) { $templatePath = ''; } From 7ee890e0ca9951fef58fc36d32a1f51a7beceded Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Fri, 1 May 2020 21:09:14 +0200 Subject: [PATCH 08/28] Replace substr()-based comparisons by substr_compare() --- plugins/PluginApi0Plugin.php | 4 ++-- plugins/ThemeApi2Plugin.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/PluginApi0Plugin.php b/plugins/PluginApi0Plugin.php index d9a40ec..05a76d1 100644 --- a/plugins/PluginApi0Plugin.php +++ b/plugins/PluginApi0Plugin.php @@ -231,8 +231,8 @@ public function onPagesLoaded( $pages = []; foreach ($plainPages as &$pageData) { if (!isset($pageData['id'])) { - if (substr($pageData['url'], 0, $baseUrlLength) === $baseUrl) { - if ($urlRewritingEnabled && (substr($pageData['url'], $baseUrlLength, 1) === '?')) { + if (substr_compare($pageData['url'], $baseUrl, 0, $baseUrlLength) === 0) { + if ($urlRewritingEnabled && (substr_compare($pageData['url'], '?', $baseUrlLength, 1) === 0)) { $pageData['id'] = substr($pageData['url'], $baseUrlLength + 1); } else { $pageData['id'] = substr($pageData['url'], $baseUrlLength); diff --git a/plugins/ThemeApi2Plugin.php b/plugins/ThemeApi2Plugin.php index bcdb9f8..e53caa8 100644 --- a/plugins/ThemeApi2Plugin.php +++ b/plugins/ThemeApi2Plugin.php @@ -138,7 +138,7 @@ public function twigEscapeStrategy($templateName) if ($templatePath) { $themePath = realpath($this->getPico()->getThemesDir() . $this->getPico()->getTheme()) . '/'; - if (substr($templatePath, 0, strlen($themePath)) === $themePath) { + if (substr_compare($templatePath, $themePath, 0, strlen($themePath)) === 0) { $themeApiVersion = $this->getPico()->getThemeApiVersion(); return ($themeApiVersion >= PicoDeprecated::API_VERSION_3) ? $escapeStrategy : false; } @@ -167,7 +167,7 @@ protected function getPluginFromPath($path) { $plugins = $this->getPico()->getPlugins(); foreach ($this->pluginPaths as $pluginName => $pluginPath) { - if ($pluginPath && (substr($path, 0, strlen($pluginPath)) === $pluginPath)) { + if ($pluginPath && (substr_compare($path, $pluginPath, 0, strlen($pluginPath)) === 0)) { return $plugins[$pluginName]; } } @@ -190,7 +190,7 @@ protected function getPluginFromPath($path) $this->pluginPaths[$pluginName] = $pluginPath; - if ($pluginPath && (substr($path, 0, strlen($pluginPath)) === $pluginPath)) { + if ($pluginPath && (substr_compare($path, $pluginPath, 0, strlen($pluginPath)) === 0)) { return $plugins[$pluginName]; } } From f933851e38a859528d51687bbe6bd8517abeca0d Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 24 Dec 2020 17:52:42 +0100 Subject: [PATCH 09/28] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7551ab3..abfdc7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,11 @@ Pico Deprecated Changelog because they are already listed in Pico's changelog. Only functional changes and/or BC-breaking changes are listed below. +### Version 3.0.0-alpha.2 +Released: 2020-12-24 + +No changes + ### Version 2.1.4 Released: 2020-08-29 From 1aa7b1d6e96f6b9a506e80868c47bfebe1892acf Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 24 Dec 2020 17:52:46 +0100 Subject: [PATCH 10/28] Version 3.0.0-alpha.2 No changes From ee906005032837bc1c8020d591234af8b9e10f92 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 6 Feb 2022 23:53:10 +0100 Subject: [PATCH 11/28] Fix Pico compatibility --- PicoDeprecated.php | 3 --- lib/AbstractPlugin.php | 10 +++++----- lib/PluginInterface.php | 2 +- plugins/PluginApi0Plugin.php | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/PicoDeprecated.php b/PicoDeprecated.php index 6be6fe2..a053bf7 100644 --- a/PicoDeprecated.php +++ b/PicoDeprecated.php @@ -16,9 +16,6 @@ * License-Filename: LICENSE */ -use picocms\Pico\AbstractPlugin as AbstractPicoPlugin; -use picocms\Pico\Pico; -use picocms\Pico\PluginInterface as PicoPluginInterface; use picocms\PicoDeprecated\Plugin\MainPlugin; use picocms\PicoDeprecated\PluginApiPluginInterface; use picocms\PicoDeprecated\PluginInterface; diff --git a/lib/AbstractPlugin.php b/lib/AbstractPlugin.php index 590ccef..59965c5 100644 --- a/lib/AbstractPlugin.php +++ b/lib/AbstractPlugin.php @@ -12,17 +12,17 @@ namespace picocms\PicoDeprecated; -use picocms\Pico\Pico; +use Pico; use PicoDeprecated; /** * Abstract class to extend from when implementing a PicoDeprecated * compatibility plugin * - * Please refer to {@see PluginInterface} for more information about how to + * Please refer to {@see PicoPluginInterface} for more information about how to * develop a PicoDeprecated compatibility plugin. * - * @see PluginInterface + * @see PicoPluginInterface * * @author Daniel Rudolf * @link http://picocms.org @@ -34,7 +34,7 @@ abstract class AbstractPlugin implements PluginInterface /** * Current instance of Pico * - * @see PluginInterface::getPico() + * @see PicoPluginInterface::getPico() * * @var Pico */ @@ -52,7 +52,7 @@ abstract class AbstractPlugin implements PluginInterface /** * List of plugins which this plugin depends on * - * @see PluginInterface::getDependencies() + * @see PicoPluginInterface::getDependencies() * * @var string[] */ diff --git a/lib/PluginInterface.php b/lib/PluginInterface.php index 8632a9d..a2eb194 100644 --- a/lib/PluginInterface.php +++ b/lib/PluginInterface.php @@ -12,7 +12,7 @@ namespace picocms\PicoDeprecated; -use picocms\Pico\Pico; +use Pico; use PicoDeprecated; /** diff --git a/plugins/PluginApi0Plugin.php b/plugins/PluginApi0Plugin.php index 05a76d1..90c9f1f 100644 --- a/plugins/PluginApi0Plugin.php +++ b/plugins/PluginApi0Plugin.php @@ -20,8 +20,8 @@ namespace picocms\PicoDeprecated\Plugin; -use picocms\Pico\Pico; use picocms\PicoDeprecated\AbstractPluginApiPlugin; +use Pico; use PicoDeprecated; use Twig\Environment as TwigEnvironment; From ea4fa66fcc6232c9368a04005220c830c29539ec Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Mon, 7 Feb 2022 00:00:32 +0100 Subject: [PATCH 12/28] Bump to API version 4 --- PicoDeprecated.php | 9 +++- plugins/PluginApi3Plugin.php | 91 ++++++++++++++++++++++++++++++++++++ plugins/ThemeApi3Plugin.php | 36 ++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 plugins/PluginApi3Plugin.php create mode 100644 plugins/ThemeApi3Plugin.php diff --git a/PicoDeprecated.php b/PicoDeprecated.php index a053bf7..6ed7d02 100644 --- a/PicoDeprecated.php +++ b/PicoDeprecated.php @@ -46,7 +46,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @var int */ - public const API_VERSION = 3; + public const API_VERSION = 4; /** * API version 0, used by Pico 0.9 and earlier @@ -76,6 +76,13 @@ class PicoDeprecated extends AbstractPicoPlugin */ public const API_VERSION_3 = 3; + /** + * API version 4, used by Pico 3.0 + * + * @var int + */ + public const API_VERSION_4 = 4; + /** * Loaded plugins, indexed by API version * diff --git a/plugins/PluginApi3Plugin.php b/plugins/PluginApi3Plugin.php new file mode 100644 index 0000000..ebaa1c9 --- /dev/null +++ b/plugins/PluginApi3Plugin.php @@ -0,0 +1,91 @@ + + * + * SPDX-License-Identifier: MIT + * License-Filename: LICENSE + */ + +namespace picocms\PicoDeprecated\Plugin; + +use picocms\PicoDeprecated\AbstractPluginApiPlugin; +use PicoDeprecated; + +/** + * Maintains backward compatibility with plugins using API version 3, written + * for Pico 2.1 + * + * @author Daniel Rudolf + * @link http://picocms.org + * @license http://opensource.org/licenses/MIT The MIT License + * @version 3.0 + */ +class PluginApi3Plugin extends AbstractPluginApiPlugin +{ + /** + * This plugin extends {@see ThemeApi3Plugin} + * + * @var string[] + */ + protected $dependsOn = [ ThemeApi3Plugin::class ]; + + /** + * Map of core events matching event signatures of older API versions + * + * @see AbstractPluginApiPlugin::handleEvent() + * + * @var array + */ + protected $eventAliases = [ + 'onPluginsLoaded' => [ 'onPluginsLoaded' ], + 'onPluginManuallyLoaded' => [ 'onPluginManuallyLoaded' ], + 'onConfigLoaded' => [ 'onConfigLoaded' ], + 'onThemeLoading' => [ 'onThemeLoading' ], + 'onThemeLoaded' => [ 'onThemeLoaded' ], + 'onRequestUrl' => [ 'onRequestUrl' ], + 'onRequestFile' => [ 'onRequestFile' ], + 'onContentLoading' => [ 'onContentLoading' ], + 'on404ContentLoading' => [ 'on404ContentLoading' ], + 'on404ContentLoaded' => [ 'on404ContentLoaded' ], + 'onContentLoaded' => [ 'onContentLoaded' ], + 'onMetaParsing' => [ 'onMetaParsing' ], + 'onMetaParsed' => [ 'onMetaParsed' ], + 'onContentParsing' => [ 'onContentParsing' ], + 'onContentPrepared' => [ 'onContentPrepared' ], + 'onContentParsed' => [ 'onContentParsed' ], + 'onPagesLoading' => [ 'onPagesLoading' ], + 'onSinglePageLoading' => [ 'onSinglePageLoading' ], + 'onSinglePageContent' => [ 'onSinglePageContent' ], + 'onSinglePageLoaded' => [ 'onSinglePageLoaded' ], + 'onPagesDiscovered' => [ 'onPagesDiscovered' ], + 'onPagesLoaded' => [ 'onPagesLoaded' ], + 'onCurrentPageDiscovered' => [ 'onCurrentPageDiscovered' ], + 'onPageTreeBuilt' => [ 'onPageTreeBuilt' ], + 'onPageRendering' => [ 'onPageRendering' ], + 'onPageRendered' => [ 'onPageRendered' ], + 'onMetaHeaders' => [ 'onMetaHeaders' ], + 'onYamlParserRegistered' => [ 'onYamlParserRegistered' ], + 'onParsedownRegistered' => [ 'onParsedownRegistered' ], + 'onTwigRegistered' => [ 'onTwigRegistered' ], + ]; + + /** + * {@inheritDoc} + */ + public function getApiVersion() + { + return PicoDeprecated::API_VERSION_4; + } + + /** + * {@inheritDoc} + */ + public function getApiVersionSupport() + { + return PicoDeprecated::API_VERSION_3; + } +} diff --git a/plugins/ThemeApi3Plugin.php b/plugins/ThemeApi3Plugin.php new file mode 100644 index 0000000..5cbdce3 --- /dev/null +++ b/plugins/ThemeApi3Plugin.php @@ -0,0 +1,36 @@ + + * + * SPDX-License-Identifier: MIT + * License-Filename: LICENSE + */ + +namespace picocms\PicoDeprecated\Plugin; + +use picocms\PicoDeprecated\AbstractPlugin; +use PicoDeprecated; + +/** + * Maintains backward compatibility with themes using API version 3, written + * for Pico 2.1 + * + * @author Daniel Rudolf + * @link http://picocms.org + * @license http://opensource.org/licenses/MIT The MIT License + * @version 3.0 + */ +class ThemeApi3Plugin extends AbstractPlugin +{ + /** + * {@inheritDoc} + */ + public function getApiVersion() + { + return PicoDeprecated::API_VERSION_4; + } +} From 8d594cb479a8d58daa89a828306ce66bec186875 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Mon, 7 Feb 2022 00:04:56 +0100 Subject: [PATCH 13/28] Travis CI: Update PHP versions --- .travis.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 12f0ccb..0dfd6f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,21 +11,17 @@ cache: jobs: include: # Test stage - - php: 7.0 - dist: xenial - - php: 7.1 - php: 7.2 - php: 7.3 - php: 7.4 + - php: 8.0 + - php: 8.1 - php: nightly - - php: hhvm-3.27 # until Sep 2019 - - php: hhvm-3.30 # until Nov 2019 # Release deployment stage - stage: deploy-release if: tag IS present - php: 7.0 - dist: xenial + php: 7.2 install: - install.sh script: From 28d5534cc5763a09599b93b2d898575e9ddcee47 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 27 Feb 2022 16:36:56 +0100 Subject: [PATCH 14/28] Update various links --- PicoDeprecated.php | 6 +++--- README.md | 2 +- composer.json | 6 +++--- lib/AbstractPlugin.php | 4 ++-- lib/AbstractPluginApiPlugin.php | 4 ++-- lib/PluginApiPluginInterface.php | 4 ++-- lib/PluginInterface.php | 4 ++-- plugins/MainPlugin.php | 4 ++-- plugins/PluginApi0Plugin.php | 4 ++-- plugins/PluginApi1Plugin.php | 4 ++-- plugins/PluginApi2Plugin.php | 4 ++-- plugins/PluginApi3Plugin.php | 4 ++-- plugins/ThemeApi0Plugin.php | 4 ++-- plugins/ThemeApi1Plugin.php | 4 ++-- plugins/ThemeApi2Plugin.php | 4 ++-- plugins/ThemeApi3Plugin.php | 4 ++-- 16 files changed, 33 insertions(+), 33 deletions(-) diff --git a/PicoDeprecated.php b/PicoDeprecated.php index 6ed7d02..d56a73b 100644 --- a/PicoDeprecated.php +++ b/PicoDeprecated.php @@ -32,11 +32,11 @@ * API versions than the one of Pico's core, even when there was just the * slightest change. * - * {@see http://picocms.org/plugins/deprecated/} for a full list of features. + * {@see https://picocms.org/plugins/deprecated/} for a full list of features. * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ class PicoDeprecated extends AbstractPicoPlugin diff --git a/README.md b/README.md index db5bd59..7378db9 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Pico Deprecated Plugin This is the repository of Pico's official `PicoDeprecated` plugin. -Pico is a stupidly simple, blazing fast, flat file CMS. See http://picocms.org/ for more info. +Pico is a stupidly simple, blazing fast, flat file CMS. See https://picocms.org/ for more info. `PicoDeprecated`'s purpose is to maintain backward compatibility to older versions of Pico, by re-introducing characteristics that were removed from Pico's core. It for example triggers old events (like the `before_render` event used before Pico 1.0) and reads config files that were written in PHP (`config/config.php`, used before Pico 2.0). diff --git a/composer.json b/composer.json index ee4adbe..6e894d8 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "pico-plugin", "description": "This is Pico's official PicoDeprecated plugin. Pico is a stupidly simple, blazing fast, flat file CMS.", "keywords": [ "pico", "picocms", "picocms-plugin", "pico-deprecated", "compatibility", "deprecation" ], - "homepage": "http://picocms.org/", + "homepage": "https://picocms.org/", "license": "MIT", "authors": [ { @@ -13,7 +13,7 @@ }, { "name": "The Pico Community", - "homepage": "http://picocms.org/" + "homepage": "https://picocms.org/" }, { "name": "Contributors", @@ -21,7 +21,7 @@ } ], "support": { - "docs": "http://picocms.org/plugins/deprecated/", + "docs": "https://picocms.org/plugins/deprecated/", "issues": "https://github.com/picocms/pico-deprecated/issues", "source": "https://github.com/picocms/pico-deprecated" }, diff --git a/lib/AbstractPlugin.php b/lib/AbstractPlugin.php index 59965c5..18a9164 100644 --- a/lib/AbstractPlugin.php +++ b/lib/AbstractPlugin.php @@ -25,8 +25,8 @@ * @see PicoPluginInterface * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ abstract class AbstractPlugin implements PluginInterface diff --git a/lib/AbstractPluginApiPlugin.php b/lib/AbstractPluginApiPlugin.php index c6a2c0a..633b0f5 100644 --- a/lib/AbstractPluginApiPlugin.php +++ b/lib/AbstractPluginApiPlugin.php @@ -22,8 +22,8 @@ * @see PluginApiPluginInterface * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ abstract class AbstractPluginApiPlugin extends AbstractPlugin implements PluginApiPluginInterface diff --git a/lib/PluginApiPluginInterface.php b/lib/PluginApiPluginInterface.php index f2bde14..1346f21 100644 --- a/lib/PluginApiPluginInterface.php +++ b/lib/PluginApiPluginInterface.php @@ -16,8 +16,8 @@ * Common interface for PicoDeprecated plugin API compatibility plugins * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ interface PluginApiPluginInterface extends PluginInterface diff --git a/lib/PluginInterface.php b/lib/PluginInterface.php index a2eb194..c7f431c 100644 --- a/lib/PluginInterface.php +++ b/lib/PluginInterface.php @@ -19,8 +19,8 @@ * Common interface for PicoDeprecated compatibility plugins * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ interface PluginInterface diff --git a/plugins/MainPlugin.php b/plugins/MainPlugin.php index c5fb93b..41391f8 100644 --- a/plugins/MainPlugin.php +++ b/plugins/MainPlugin.php @@ -27,8 +27,8 @@ * Maintains backward compatibility with older Pico versions * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ class MainPlugin extends AbstractPlugin diff --git a/plugins/PluginApi0Plugin.php b/plugins/PluginApi0Plugin.php index 90c9f1f..7145c90 100644 --- a/plugins/PluginApi0Plugin.php +++ b/plugins/PluginApi0Plugin.php @@ -30,8 +30,8 @@ * for Pico 0.9 and earlier * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ class PluginApi0Plugin extends AbstractPluginApiPlugin diff --git a/plugins/PluginApi1Plugin.php b/plugins/PluginApi1Plugin.php index 9bf624e..581de4b 100644 --- a/plugins/PluginApi1Plugin.php +++ b/plugins/PluginApi1Plugin.php @@ -29,8 +29,8 @@ * for Pico 1.0 * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ class PluginApi1Plugin extends AbstractPluginApiPlugin diff --git a/plugins/PluginApi2Plugin.php b/plugins/PluginApi2Plugin.php index 6cb9b70..c98982c 100644 --- a/plugins/PluginApi2Plugin.php +++ b/plugins/PluginApi2Plugin.php @@ -28,8 +28,8 @@ * for Pico 2.0 * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ class PluginApi2Plugin extends AbstractPluginApiPlugin diff --git a/plugins/PluginApi3Plugin.php b/plugins/PluginApi3Plugin.php index ebaa1c9..d52a459 100644 --- a/plugins/PluginApi3Plugin.php +++ b/plugins/PluginApi3Plugin.php @@ -20,8 +20,8 @@ * for Pico 2.1 * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ class PluginApi3Plugin extends AbstractPluginApiPlugin diff --git a/plugins/ThemeApi0Plugin.php b/plugins/ThemeApi0Plugin.php index c93bf1f..c823d45 100644 --- a/plugins/ThemeApi0Plugin.php +++ b/plugins/ThemeApi0Plugin.php @@ -34,8 +34,8 @@ * version 0. * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ class ThemeApi0Plugin extends AbstractPlugin diff --git a/plugins/ThemeApi1Plugin.php b/plugins/ThemeApi1Plugin.php index 6d62770..ecfec8a 100644 --- a/plugins/ThemeApi1Plugin.php +++ b/plugins/ThemeApi1Plugin.php @@ -29,8 +29,8 @@ * for Pico 1.0 * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ class ThemeApi1Plugin extends AbstractPlugin diff --git a/plugins/ThemeApi2Plugin.php b/plugins/ThemeApi2Plugin.php index e53caa8..ec8723f 100644 --- a/plugins/ThemeApi2Plugin.php +++ b/plugins/ThemeApi2Plugin.php @@ -32,8 +32,8 @@ * for Pico 2.0 * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ class ThemeApi2Plugin extends AbstractPlugin diff --git a/plugins/ThemeApi3Plugin.php b/plugins/ThemeApi3Plugin.php index 5cbdce3..3589a49 100644 --- a/plugins/ThemeApi3Plugin.php +++ b/plugins/ThemeApi3Plugin.php @@ -20,8 +20,8 @@ * for Pico 2.1 * * @author Daniel Rudolf - * @link http://picocms.org - * @license http://opensource.org/licenses/MIT The MIT License + * @link https://picocms.org + * @license https://opensource.org/licenses/MIT The MIT License * @version 3.0 */ class ThemeApi3Plugin extends AbstractPlugin From 1dbb3c9e96b182d5dd48d504330b8bfc3bfec5d2 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 6 Mar 2022 16:43:48 +0100 Subject: [PATCH 15/28] CI: Update Stale Bot config --- .github/workflows/stale.yml | 53 ++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 878d942..5ca512e 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -1,28 +1,33 @@ -name: "Mark or close stale issues and PRs" +name: Mark or close stale issues and PRs + on: - schedule: - - cron: "0 12 * * *" + schedule: + - cron: "0 */6 * * *" jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v3 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - days-before-stale: 7 - days-before-close: 2 - stale-issue-message: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed in two days if no further activity - occurs. Thank you for your contributions! :+1: - stale-pr-message: > - This pull request has been automatically marked as stale because it has not had - recent activity. It will be closed in two days if no further activity - occurs. Thank you for your contributions! :+1: - stale-pr-label: "info: Stale" - stale-issue-label: "info: Stale" - exempt-issue-labels: "type: Bug,type: Enhancement,type: Feature,type: Idea,type: Release,info: Pinned" - exempt-pr-labels: "type: Bug,type: Enhancement,type: Feature,type: Idea,type: Release,info: Pinned" - remove-stale-when-updated: true + stale: + name: Mark or close stale issues and PRs + + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/stale@v3 + with: + days-before-stale: 7 + days-before-close: 2 + stale-issue-message: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed in two days if no further activity + occurs. Thank you for your contributions! :+1: + stale-pr-message: > + This pull request has been automatically marked as stale because it has not had + recent activity. It will be closed in two days if no further activity + occurs. Thank you for your contributions! :+1: + stale-pr-label: "info: Stale" + stale-issue-label: "info: Stale" + exempt-issue-labels: "type: Bug,type: Enhancement,type: Feature,type: Idea,type: Release,info: Pinned" + exempt-pr-labels: "type: Bug,type: Enhancement,type: Feature,type: Idea,type: Release,info: Pinned" + remove-stale-when-updated: true From f8f28f9791c5518b6457c30a62e0430fbca37f87 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 6 Mar 2022 17:02:16 +0100 Subject: [PATCH 16/28] Add PicoDeprecated::VERSION and PicoDeprecated::VERSION_ID constants --- PicoDeprecated.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/PicoDeprecated.php b/PicoDeprecated.php index d56a73b..c16b1ad 100644 --- a/PicoDeprecated.php +++ b/PicoDeprecated.php @@ -41,6 +41,20 @@ */ class PicoDeprecated extends AbstractPicoPlugin { + /** + * PicoDeprecated version + * + * @var string + */ + public const VERSION = '3.0.0-dev'; + + /** + * PicoDeprecated version ID + * + * @var int + */ + public const VERSION_ID = 30000; + /** * API version used by this plugin * From e31463cecb2350cadb1815bd02aa78527ee121b9 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 6 Mar 2022 16:54:21 +0100 Subject: [PATCH 17/28] CI: Add GitHub workflow 'test' Runs `composer install` and `phpcs` on basically every push, replaces Travis CI (which was never actually in use here, but nevertheless...). --- .gitattributes | 1 - .github/workflows/test.yml | 102 +++++++++++++++++++++++++++++++++++++ .travis.yml | 58 --------------------- 3 files changed, 102 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.gitattributes b/.gitattributes index 0eacfff..1475def 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,4 +3,3 @@ /.gitattributes export-ignore /.gitignore export-ignore /.phpcs.xml export-ignore -/.travis.yml export-ignore diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d2c7030 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,102 @@ +name: Test PicoDeprecated + +on: + push: + branches: + - 'master' + - 'pico-3.0' + tags: [ 'v*.*.*' ] + pull_request: {} + workflow_call: {} + +jobs: + test: + name: PHP ${{ matrix.PHP_VERSION }} + + runs-on: ubuntu-latest + permissions: + contents: read + + strategy: + matrix: + PHP_VERSION: + - '7.2' + - '7.3' + - '7.4' + - '8.0' + - '8.1' + - 'nightly' + fail-fast: false + + continue-on-error: ${{ matrix.PHP_VERSION == 'nightly' }} + + env: + PHP_VERSION: ${{ matrix.PHP_VERSION }} + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup PHP ${{ env.PHP_VERSION }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ env.PHP_VERSION }} + tools: composer, phpcs + + - name: Setup Composer auth + run: | + composer config --global github-oauth.github.com "${{ github.token }}" + + - name: Get Composer cache directory + run: | + COMPOSER_CACHE_DIR="$(composer config --global cache-dir)" + echo "COMPOSER_CACHE_DIR=$COMPOSER_CACHE_DIR" | tee -a "$GITHUB_ENV" + + - name: Restore Composer cache + uses: actions/cache@v2 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: ${{ runner.os }}-composer-php${{ env.PHP_VERSION }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Setup Composer root version + if: ${{ github.ref_type == 'branch' }} + run: | + COMPOSER_ROOT_VERSION= + + COMPOSER_ROOT_VERSION="$(composer config \ + extra.branch-alias."dev-${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" \ + 2> /dev/null || true)" + + if [ -z "$COMPOSER_ROOT_VERSION" ]; then + COMPOSER_ROOT_VERSION="$(php -r " + class AbstractPicoPlugin {} + require('./PicoDeprecated.php'); + echo preg_replace('/\.[0-9]+-dev$/', '.x-dev', PicoDeprecated::VERSION); + ")" + fi + + echo "COMPOSER_ROOT_VERSION=$COMPOSER_ROOT_VERSION" | tee -a "$GITHUB_ENV" + + - name: Install Composer dependencies + run: | + composer install + + - name: Read PicoDeprecated version + run: | + VERSION="$(php -r " + class AbstractPicoPlugin {} + require('./PicoDeprecated.php'); + echo PicoDeprecated::VERSION; + ")" + echo "VERSION=$VERSION" | tee -a "$GITHUB_ENV" + + - name: Check PicoDeprecated version + if: ${{ github.ref_type == 'tag' }} + run: | + [ "$GITHUB_REF_NAME" == "v$VERSION" ] + + - name: Run PHP_CodeSniffer + run: | + phpcs --standard=.phpcs.xml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0dfd6f9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,58 +0,0 @@ -os: linux -dist: bionic -sudo: false - -language: php - -cache: - directories: - - $HOME/.composer/cache/files - -jobs: - include: - # Test stage - - php: 7.2 - - php: 7.3 - - php: 7.4 - - php: 8.0 - - php: 8.1 - - php: nightly - - # Release deployment stage - - stage: deploy-release - if: tag IS present - php: 7.2 - install: - - install.sh - script: - - 'true' - before_deploy: - - release.sh "$PROJECT_REPO_TAG" - deploy: - provider: releases - api_key: ${GITHUB_OAUTH_TOKEN} - file: - - pico-deprecated-release-$PROJECT_REPO_TAG.tar.gz - - pico-deprecated-release-$PROJECT_REPO_TAG.zip - skip_cleanup: true - name: Version ${PROJECT_REPO_TAG:1} - draft: true - on: - tags: true - - # Ignore nightly build failures - allow_failures: - - php: nightly - fast_finish: true - -before_install: - - export PICO_TOOLS_DIR="$HOME/__picocms_tools" - - git clone --branch="$TOOLS_REPO_BRANCH" "https://github.com/$TOOLS_REPO_SLUG.git" "$PICO_TOOLS_DIR" - - . "$PICO_TOOLS_DIR/init/travis.sh.inc" - - . "$PICO_PROJECT_DIR/.build/init.sh.inc" - -install: - - install.sh - -script: - - phpcs --standard=.phpcs.xml "$PICO_PROJECT_DIR" From 4482fd20fda4e0e4a2a290fb664d1e20802126b0 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 8 Mar 2022 22:10:41 +0100 Subject: [PATCH 18/28] CI: Add build script to build and publish new releases This is more or less a copy of Pico's new CI pipeline. It heavily refactors and simplifies the CI pipeline and now uses the GitHub CLI `gh` to deploy new releases. You can use the Makefile to both just build new releases (possibly just locally), and to also publish them. PicoDeprecated's build script no longer depends on any external resources (like our `picocms/ci-tools` collection), but on a few runtime dependencies (namely `git`, `rsync`, and `jq`, as well as the GitHub CLI `gh` with working authentication). --- .build/build.sh | 310 +++++++++++++++++++++++++++++++++++++++++++++ .build/clean.sh | 21 --- .build/init.sh.inc | 7 - .build/install.sh | 11 -- .build/release.sh | 49 ------- .gitignore | 3 - Makefile | 55 ++++++++ 7 files changed, 365 insertions(+), 91 deletions(-) create mode 100755 .build/build.sh delete mode 100755 .build/clean.sh delete mode 100644 .build/init.sh.inc delete mode 100755 .build/install.sh delete mode 100755 .build/release.sh create mode 100644 Makefile diff --git a/.build/build.sh b/.build/build.sh new file mode 100755 index 0000000..8818a31 --- /dev/null +++ b/.build/build.sh @@ -0,0 +1,310 @@ +#!/bin/bash +# PicoDeprecated -- build.sh +# Builds a new PicoDeprecated release and creates release archives. +# +# This file is part of Pico, a stupidly simple, blazing fast, flat file CMS. +# Visit us at https://picocms.org/ for more info. +# +# Copyright (c) 2019 Daniel Rudolf +# +# This work is licensed under the terms of the MIT license. +# For a copy, see LICENSE file or . +# +# SPDX-License-Identifier: MIT +# License-Filename: LICENSE + +set -eu -o pipefail +export LC_ALL=C + +# env variables +PHP="${PHP:-php}" +export -n PHP + +COMPOSER="${COMPOSER:-composer}" +export -n COMPOSER + +if ! which "$PHP" > /dev/null; then + echo "Missing script dependency: php" >&2 + exit 1 +elif ! which "$COMPOSER" > /dev/null; then + echo "Missing script dependency: composer" >&2 + exit 1 +elif ! which "git" > /dev/null; then + echo "Missing script dependency: git" >&2 + exit 1 +elif ! which "gh" > /dev/null; then + echo "Missing script dependency: gh" >&2 + exit 1 +elif ! which "rsync" > /dev/null; then + echo "Missing script dependency: rsync" >&2 + exit 1 +elif ! which "jq" > /dev/null; then + echo "Missing script dependency: jq" >&2 + exit 1 +fi + +# parameters +BUILD_NAME="pico-deprecated" +BUILD_PROJECT="picocms/pico-deprecated" +BUILD_VERSION= + +PICO_PROJECT="picocms/pico" + +PHP_VERSION="7.2" + +# options +VERSION= +PUBLISH= +NOCHECK= +NOCLEAN= + +while [ $# -gt 0 ]; do + if [ "$1" == "--help" ]; then + echo "Usage:" + echo " build.sh [OPTIONS]... [VERSION]" + echo + echo "Builds a new PicoDeprecated release and creates release archives." + echo + echo "Help options:" + echo " --help display this help and exit" + echo + echo "Application options:" + echo " --publish create GitHub release and upload artifacts" + echo " --no-check skip version checks for dev builds" + echo " --no-clean don't remove build dir on exit" + echo + echo "You must run this script from within PicoDeprecated's source directory." + echo "Please note that this script will perform a large number of strict sanity" + echo "checks before building a new non-development version of PicoDeprecated." + echo "VERSION must start with 'v'." + exit 0 + elif [ "$1" == "--publish" ]; then + PUBLISH="y" + shift + elif [ "$1" == "--no-check" ]; then + NOCHECK="y" + shift + elif [ "$1" == "--no-clean" ]; then + NOCLEAN="y" + shift + elif [ -z "$VERSION" ] && [ "${1:0:1}" == "v" ]; then + VERSION="$1" + shift + else + echo "Unknown option: $1" >&2 + exit 1 + fi +done + +# check options and current working dir +if [ ! -f "./composer.json" ] || [ ! -f "./PicoDeprecated.php" ]; then + echo "You must run this from within PicoDeprecated's source directory" >&2 + exit 1 +elif [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" != "true" ]; then + echo "You must run this from within a non-bare Git repository" >&2 + exit 1 +fi + +# parse version +function parse_version { + VERSION_FULL="${1#v}" + + if ! [[ "$VERSION_FULL" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z\.\-]+))?(\+([0-9A-Za-z\.\-]+))?$ ]]; then + return 1 + fi + + VERSION_MAJOR="${BASH_REMATCH[1]}" + VERSION_MINOR="${BASH_REMATCH[2]}" + VERSION_PATCH="${BASH_REMATCH[3]}" + VERSION_SUFFIX="${BASH_REMATCH[5]}" + + VERSION_STABILITY="stable" + if [[ "$VERSION_SUFFIX" =~ ^(dev|a|alpha|b|beta|rc)?([.-]?[0-9]+)?([.-](dev))?$ ]]; then + if [ "${BASH_REMATCH[1]}" == "dev" ] || [ "${BASH_REMATCH[4]}" == "dev" ]; then + VERSION_STABILITY="dev" + elif [ "${BASH_REMATCH[1]}" == "a" ] || [ "${BASH_REMATCH[1]}" == "alpha" ]; then + VERSION_STABILITY="alpha" + elif [ "${BASH_REMATCH[1]}" == "b" ] || [ "${BASH_REMATCH[1]}" == "beta" ]; then + VERSION_STABILITY="beta" + elif [ "${BASH_REMATCH[1]}" == "rc" ]; then + VERSION_STABILITY="rc" + fi + fi +} + +export COMPOSER_ROOT_VERSION= + +BUILD_VERSION="v$("$PHP" -r 'class AbstractPicoPlugin {} require("./PicoDeprecated.php"); echo PicoDeprecated::VERSION;')" + +if ! parse_version "$BUILD_VERSION"; then + echo "Unable to build PicoDeprecated: Invalid PicoDeprecated version '$BUILD_VERSION'" >&2 + exit 1 +fi + +if [ -z "$VERSION" ]; then + GIT_LOCAL_HEAD="$(git rev-parse HEAD)" + GIT_LOCAL_BRANCH="$(git rev-parse --abbrev-ref HEAD)" + DATETIME="$(date -u +'%Y%m%dT%H%M%SZ')" + + VERSION="v$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" + [ -z "$VERSION_SUFFIX" ] || VERSION+="-$VERSION_SUFFIX" + [ "$VERSION_STABILITY" == "dev" ] || VERSION+="-dev" + VERSION+="+git.$GIT_LOCAL_HEAD.$DATETIME" + + if ! parse_version "$VERSION"; then + echo "Unable to build PicoDeprecated: Invalid build version '$VERSION'" >&2 + exit 1 + fi + + COMPOSER_ROOT_VERSION="dev-$GIT_LOCAL_BRANCH" +else + if ! parse_version "$VERSION"; then + echo "Unable to build PicoDeprecated: Invalid build version '$VERSION'" >&2 + exit 1 + fi + + if [ "$VERSION_STABILITY" == "dev" ]; then + COMPOSER_ROOT_VERSION="$(jq -r --arg ALIAS "$VERSION_MAJOR.$VERSION_MINOR.x-dev" \ + '.extra."branch-alias"|to_entries|map(select(.value==$ALIAS).key)[0]//empty' \ + "composer.json")" + fi + + if [ -z "$COMPOSER_ROOT_VERSION" ]; then + COMPOSER_ROOT_VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" + [ -z "$VERSION_SUFFIX" ] || COMPOSER_ROOT_VERSION+="-$VERSION_SUFFIX" + [ "$VERSION_STABILITY" == "stable" ] || COMPOSER_ROOT_VERSION+="@$VERSION_STABILITY" + fi +fi + +# build checks +if [ "$VERSION_STABILITY" != "dev" ]; then + GIT_LOCAL_CLEAN="$(git status --porcelain)" + GIT_LOCAL_HEAD="$(git rev-parse HEAD)" + GIT_LOCAL_TAG="$(git rev-parse --verify "refs/tags/$VERSION" 2> /dev/null || true)" + GIT_REMOTE="$(git 'for-each-ref' --format='%(upstream:remotename)' "$(git symbolic-ref -q HEAD)")" + GIT_REMOTE_TAG="$(git ls-remote "${GIT_REMOTE:-origin}" "refs/tags/$VERSION" 2> /dev/null | cut -f 1 || true)" + PHP_VERSION_LOCAL="$("$PHP" -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')" + + if [ "$VERSION" != "$BUILD_VERSION" ]; then + echo "Unable to build PicoDeprecated: Building $VERSION, but PicoDeprecated indicates $BUILD_VERSION" >&2 + exit 1 + elif [ -n "$GIT_LOCAL_CLEAN" ]; then + echo "Unable to build PicoDeprecated: Building $VERSION, but the working tree is not clean" >&2 + exit 1 + elif [ -z "$GIT_LOCAL_TAG" ]; then + echo "Unable to build PicoDeprecated: Building $VERSION, but no matching local Git tag was found" >&2 + exit 1 + elif [ "$GIT_LOCAL_HEAD" != "$GIT_LOCAL_TAG" ]; then + echo "Unable to build PicoDeprecated: Building $VERSION, but the matching Git tag is not checked out" >&2 + exit 1 + elif [ -z "$GIT_REMOTE_TAG" ]; then + echo "Unable to build PicoDeprecated: Building $VERSION, but no matching remote Git tag was found" >&2 + exit 1 + elif [ "$GIT_LOCAL_TAG" != "$GIT_REMOTE_TAG" ]; then + echo "Unable to build PicoDeprecated: Building $VERSION, but the matching local and remote Git tags differ" >&2 + exit 1 + elif [ "$PHP_VERSION_LOCAL" != "$PHP_VERSION" ]; then + echo "Unable to build PicoDeprecated: Refusing to build PicoDeprecated with PHP $PHP_VERSION_LOCAL, expecting PHP $PHP_VERSION" >&2 + exit 1 + fi +else + if [ -z "$NOCHECK" ] && [[ "$VERSION" != "$BUILD_VERSION"* ]]; then + echo "Unable to build PicoDeprecated: Building $VERSION, but PicoDeprecated indicates $BUILD_VERSION" >&2 + exit 1 + elif [ -n "$PUBLISH" ]; then + echo "Unable to build PicoDeprecated: Refusing to publish a dev version" >&2 + exit 1 + fi +fi + +# build in progress... +APP_DIR="$PWD" + +BUILD_DIR="$(mktemp -d)" +[ -n "$NOCLEAN" ] || trap "rm -rf ${BUILD_DIR@Q}" ERR EXIT + +echo "Building Pico $BUILD_VERSION ($VERSION)..." +[ -z "$NOCLEAN" ] || echo "Build directory: $BUILD_DIR" +echo + +# copy PicoDeprecated for building +# the working tree is always clean for non-dev versions, see build checks above +echo "Creating clean working tree copy of '$BUILD_PROJECT'..." +rsync -a \ + --exclude="/.build" \ + --exclude="/.git" \ + --exclude="/.github" \ + --exclude="/.gitattributes" \ + --exclude="/.gitignore" \ + --exclude="/.phpcs.xml" \ + --exclude-from=<(git ls-files --exclude-standard -oi --directory) \ + ./ "$BUILD_DIR/" + +echo + +# switch to build dir... +cd "$BUILD_DIR" + +# remove picocms/pico dependency +echo "Removing '$PICO_PROJECT' dependency..." +"$COMPOSER" remove --no-update "$PICO_PROJECT" +echo + +# set minimum stability +if [ "$VERSION_STABILITY" != "stable" ]; then + echo "Setting minimum stability to '$VERSION_STABILITY'..." + "$COMPOSER" config "minimum-stability" "$VERSION_STABILITY" + "$COMPOSER" config "prefer-stable" "true" + echo +fi + +# install dependencies +echo "Installing Composer dependencies..." +"$COMPOSER" install --no-dev --optimize-autoloader +echo + +# prepare release +echo "Removing '.git' directory..." +rm -rf .git + +echo "Removing '.git' directories of dependencies..." +find vendor/ -type d -path 'vendor/*/*/.git' -print0 | xargs -0 rm -rf + +echo + +# restore picocms/pico dependency +# FIXME: https://github.com/composer/composer/issues/10593 +#echo "Restoring '$PICO_PROJECT' dependency..." +#"$COMPOSER" require --no-update "$PICO_PROJECT self.version" +#echo + +# create release archives +ARCHIVE_FILENAME="$BUILD_NAME-release-$VERSION" + +echo "Creating release archive '$ARCHIVE_FILENAME.tar.gz'..." +find . -mindepth 1 -maxdepth 1 -printf '%f\0' \ + | xargs -0 -- tar -czf "$APP_DIR/$ARCHIVE_FILENAME.tar.gz" -- + +echo "Creating release archive '$ARCHIVE_FILENAME.zip'..." +zip -q -r "$APP_DIR/$ARCHIVE_FILENAME.zip" . + +echo + +# publish release +if [ -n "$PUBLISH" ]; then + # switch to app dir + cd "$APP_DIR" + + # create GitHub release and upload release archives + echo "Creating GitHub release and uploading release archives..." + + GITHUB_PRERELEASE= + [ "$VERSION_STABILITY" == "stable" ] || GITHUB_PRERELEASE="--prerelease" + + gh release create "$VERSION" \ + --title "Version $VERSION_FULL" \ + --generate-notes \ + "$GITHUB_PRERELEASE" \ + "$APP_DIR/$ARCHIVE_FILENAME.tar.gz" \ + "$APP_DIR/$ARCHIVE_FILENAME.zip" +fi diff --git a/.build/clean.sh b/.build/clean.sh deleted file mode 100755 index 0c44328..0000000 --- a/.build/clean.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -set -e - -[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; } - -# parameters -ARCHIVE_DIR="${1:-$PICO_PROJECT_DIR}" # directory to create release archives in - -# print parameters -echo "Cleaning up build environment..." -printf 'PICO_BUILD_DIR="%s"\n' "$PICO_BUILD_DIR" -printf 'ARCHIVE_DIR="%s"\n' "$ARCHIVE_DIR" -echo - -echo "Removing build directory..." -[ ! -d "$PICO_BUILD_DIR" ] || rm -rf "$PICO_BUILD_DIR" - -echo "Removing release archives..." -find "$ARCHIVE_DIR" -mindepth 1 -maxdepth 1 \ - \( -name 'pico-deprecated-release-*.tar.gz' -o -name 'pico-deprecated-release-*.zip' \) \ - -delete diff --git a/.build/init.sh.inc b/.build/init.sh.inc deleted file mode 100644 index 80828e7..0000000 --- a/.build/init.sh.inc +++ /dev/null @@ -1,7 +0,0 @@ -if [ -z "$PICO_BUILD_ENV" ]; then - echo "No Pico build environment specified" >&2 - exit 1 -fi - -# add project build dir to $PATH -export PATH="$PICO_PROJECT_DIR/.build:$PATH" diff --git a/.build/install.sh b/.build/install.sh deleted file mode 100755 index 59b89bb..0000000 --- a/.build/install.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -e - -[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; } - -# setup build system -"$PICO_TOOLS_DIR/setup/$PICO_BUILD_ENV.sh" --phpcs - -# install dependencies -echo "Running \`composer install\`..." -composer install --no-suggest diff --git a/.build/release.sh b/.build/release.sh deleted file mode 100755 index be64be3..0000000 --- a/.build/release.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash -set -e - -[ -n "$PICO_BUILD_ENV" ] || { echo "No Pico build environment specified" >&2; exit 1; } - -# parameters -VERSION="${1:-$PROJECT_REPO_TAG}" # version to create a release for -ARCHIVE_DIR="${2:-$PICO_PROJECT_DIR}" # directory to create release archives in - -# print parameters -echo "Creating new release..." -printf 'VERSION="%s"\n' "$VERSION" -echo - -# set archive name -if [ -n "$VERSION" ]; then - ARCHIVE_NAME="pico-deprecated-release-v${VERSION#v}" -else - ARCHIVE_NAME="pico-deprecated-release-dev-${PROJECT_REPO_BRANCH:-master}" -fi - -# copy project -rsync -a \ - --exclude="/.git" \ - --exclude="/.build" \ - --exclude="/.github" \ - --exclude="/.gitattributes" \ - --exclude="/.gitignore" \ - --exclude="/.phpcs.xml" \ - --exclude="/.travis.yml" \ - --exclude="/pico-deprecated-release-v*.tar.gz" \ - --exclude="/pico-deprecated-release-v*.zip" \ - "$PICO_PROJECT_DIR/" \ - "$PICO_BUILD_DIR/" - -cd "$PICO_BUILD_DIR" - -# remove picocms/Pico dependency -echo "Removing 'picocms/pico' dependency..." -composer remove --no-update "picocms/pico" -echo - -# install dependencies -echo "Running \`composer install\`..." -composer install --no-suggest --prefer-dist --no-dev --optimize-autoloader -echo - -# create release archives -create-release.sh "$PICO_BUILD_DIR" "$ARCHIVE_DIR" "$ARCHIVE_NAME" diff --git a/.gitignore b/.gitignore index 70ac336..e9e1e3e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,5 @@ desktop.ini /vendor # Build system -/.build/build -/.build/deploy -/.build/ci-tools /pico-deprecated-release-*.tar.gz /pico-deprecated-release-*.zip diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..82a1952 --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ +# PicoDeprecated -- Makefile +# Makefile to build new PicoDeprecated releases using './.build/build.sh'. +# +# This file is part of Pico, a stupidly simple, blazing fast, flat file CMS. +# Visit us at https://picocms.org/ for more info. +# +# Copyright (c) 2022 Daniel Rudolf +# +# This work is licensed under the terms of the MIT license. +# For a copy, see LICENSE file or . +# +# SPDX-License-Identifier: MIT +# License-Filename: LICENSE + +version?= +nocheck?=false +publish=false + +php?=php +composer?=composer + +app_name=pico-deprecated +archive_tar=$(app_name)-release-*.tar.gz +archive_zip=$(app_name)-release-*.zip +export=$(app_name)-export.tar.gz + +all: clean build + +clean: clean-build clean-export + +clean-build: + find "." -name "$(archive_tar)" -exec rm -f {} \; + find "." -name "$(archive_zip)" -exec rm -f {} \; + +clean-export: + rm -f "./$(export)" + +build: export PHP=$(php) +build: export COMPOSER=$(composer) +build: + ./.build/build.sh$(if $(filter true,$(publish)), --publish,)$(if $(filter true,$(nocheck)), --no-check,)$(if $(version), "$(version)",) + +export: + git archive --prefix "$(app_name)/" -o "./$(export)" HEAD + +publish: publish=true +publish: build + +composer: + $(composer) install --optimize-autoloader --no-dev + +.PHONY: all \ + clean clean-build clean-export \ + build export publish \ + composer From 7a2992c6dfae8258f98e21344fc5142dc766034d Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 8 Mar 2022 23:34:44 +0100 Subject: [PATCH 19/28] Enable PHP strict typing --- PicoDeprecated.php | 26 ++++++++++++----------- lib/AbstractPlugin.php | 10 +++++---- lib/AbstractPluginApiPlugin.php | 8 ++++--- lib/PluginApiPluginInterface.php | 6 ++++-- lib/PluginInterface.php | 12 ++++++----- plugins/MainPlugin.php | 8 ++++--- plugins/PluginApi0Plugin.php | 30 +++++++++++++------------- plugins/PluginApi1Plugin.php | 36 +++++++++++++++++--------------- plugins/PluginApi2Plugin.php | 10 +++++---- plugins/PluginApi3Plugin.php | 6 ++++-- plugins/ThemeApi0Plugin.php | 4 +++- plugins/ThemeApi1Plugin.php | 12 ++++++----- plugins/ThemeApi2Plugin.php | 14 +++++++------ plugins/ThemeApi3Plugin.php | 4 +++- 14 files changed, 107 insertions(+), 79 deletions(-) diff --git a/PicoDeprecated.php b/PicoDeprecated.php index c16b1ad..570cd8b 100644 --- a/PicoDeprecated.php +++ b/PicoDeprecated.php @@ -16,6 +16,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + use picocms\PicoDeprecated\Plugin\MainPlugin; use picocms\PicoDeprecated\PluginApiPluginInterface; use picocms\PicoDeprecated\PluginInterface; @@ -173,7 +175,7 @@ public function handleEvent($eventName, array $params) * * @param object[] $plugins loaded plugin instances */ - public function onPluginsLoaded(array $plugins) + public function onPluginsLoaded(array $plugins): void { $this->loadCompatPlugin(MainPlugin::class); @@ -192,7 +194,7 @@ public function onPluginsLoaded(array $plugins) * * @param object $plugin loaded plugin instance */ - public function onPluginManuallyLoaded($plugin) + public function onPluginManuallyLoaded(object $plugin): void { $this->loadPlugin($plugin); } @@ -204,7 +206,7 @@ public function onPluginManuallyLoaded($plugin) * @param int $themeApiVersion API version of the theme * @param array $themeConfig config array of the theme */ - public function onThemeLoaded($theme, $themeApiVersion, array &$themeConfig) + public function onThemeLoaded(string $theme, int $themeApiVersion, array &$themeConfig): void { $this->loadThemeApiCompatPlugin($themeApiVersion); } @@ -218,7 +220,7 @@ public function onThemeLoaded($theme, $themeApiVersion, array &$themeConfig) * * @param object $plugin loaded plugin instance */ - protected function loadPlugin($plugin) + protected function loadPlugin(object $plugin): void { $pluginName = get_class($plugin); @@ -238,7 +240,7 @@ protected function loadPlugin($plugin) * * @return object[] loaded plugin instances */ - public function getPlugins($apiVersion) + public function getPlugins(int $apiVersion): array { return isset($this->plugins[$apiVersion]) ? $this->plugins[$apiVersion] : []; } @@ -251,7 +253,7 @@ public function getPlugins($apiVersion) * * @return PluginInterface instance of the loaded plugin */ - public function loadCompatPlugin($plugin) + public function loadCompatPlugin($plugin): PluginInterface { if (!is_object($plugin)) { $className = (string) $plugin; @@ -294,7 +296,7 @@ public function loadCompatPlugin($plugin) * * @param int $apiVersion API version to load the compatibility plugin for */ - protected function loadPluginApiCompatPlugin($apiVersion) + protected function loadPluginApiCompatPlugin(int $apiVersion): void { if ($apiVersion !== static::API_VERSION) { $this->loadCompatPlugin('picocms\PicoDeprecated\Plugin\PluginApi' . $apiVersion . 'Plugin'); @@ -306,7 +308,7 @@ protected function loadPluginApiCompatPlugin($apiVersion) * * @param int $apiVersion API version to load the compatibility plugin for */ - protected function loadThemeApiCompatPlugin($apiVersion) + protected function loadThemeApiCompatPlugin(int $apiVersion): void { if ($apiVersion !== static::API_VERSION) { $this->loadCompatPlugin('picocms\PicoDeprecated\Plugin\ThemeApi' . $apiVersion . 'Plugin'); @@ -318,7 +320,7 @@ protected function loadThemeApiCompatPlugin($apiVersion) * * @return PluginInterface[] list of loaded compatibility plugins */ - public function getCompatPlugins() + public function getCompatPlugins(): array { return $this->compatPlugins; } @@ -338,7 +340,7 @@ public function getCompatPlugins() * @param string $eventName event to trigger * @param array $params optional parameters to pass */ - public function triggerEvent($apiVersion, $eventName, array $params = []) + public function triggerEvent(int $apiVersion, string $eventName, array $params = []): void { foreach ($this->getPlugins($apiVersion) as $plugin) { $plugin->handleEvent($eventName, $params); @@ -352,7 +354,7 @@ public function triggerEvent($apiVersion, $eventName, array $params = []) * * @return int API version used by the plugin */ - public function getPluginApiVersion($plugin) + public function getPluginApiVersion(object $plugin): int { $pluginApiVersion = self::API_VERSION_0; if ($plugin instanceof PicoPluginInterface) { @@ -370,7 +372,7 @@ public function getPluginApiVersion($plugin) * * @return string[] list of Pico's core events */ - public function getCoreEvents() + public function getCoreEvents(): array { return [ 'onPluginsLoaded', diff --git a/lib/AbstractPlugin.php b/lib/AbstractPlugin.php index 18a9164..80804f7 100644 --- a/lib/AbstractPlugin.php +++ b/lib/AbstractPlugin.php @@ -10,6 +10,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated; use Pico; @@ -73,7 +75,7 @@ public function __construct(Pico $pico, PicoDeprecated $picoDeprecated) /** * {@inheritDoc} */ - public function handleEvent($eventName, array $params) + public function handleEvent(string $eventName, array $params): void { if (method_exists($this, $eventName)) { call_user_func_array([ $this, $eventName ], $params); @@ -83,7 +85,7 @@ public function handleEvent($eventName, array $params) /** * {@inheritDoc} */ - public function getPico() + public function getPico(): Pico { return $this->pico; } @@ -91,7 +93,7 @@ public function getPico() /** * {@inheritDoc} */ - public function getPicoDeprecated() + public function getPicoDeprecated(): PicoDeprecated { return $this->picoDeprecated; } @@ -99,7 +101,7 @@ public function getPicoDeprecated() /** * {@inheritDoc} */ - public function getDependencies() + public function getDependencies(): array { return (array) $this->dependsOn; } diff --git a/lib/AbstractPluginApiPlugin.php b/lib/AbstractPluginApiPlugin.php index 633b0f5..96cf1ee 100644 --- a/lib/AbstractPluginApiPlugin.php +++ b/lib/AbstractPluginApiPlugin.php @@ -10,6 +10,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated; /** @@ -40,7 +42,7 @@ abstract class AbstractPluginApiPlugin extends AbstractPlugin implements PluginA /** * {@inheritDoc} */ - public function handleEvent($eventName, array $params) + public function handleEvent(string $eventName, array $params): void { parent::handleEvent($eventName, $params); @@ -55,7 +57,7 @@ public function handleEvent($eventName, array $params) /** * {@inheritDoc} */ - public function handleCustomEvent($eventName, array $params = []) + public function handleCustomEvent(string $eventName, array $params = []): void { $this->getPicoDeprecated()->triggerEvent($this->getApiVersionSupport(), $eventName, $params); } @@ -66,7 +68,7 @@ public function handleCustomEvent($eventName, array $params = []) * @param string $eventName name of the event to trigger * @param array $params optional parameters to pass */ - protected function triggerEvent($eventName, array $params = []) + protected function triggerEvent(string $eventName, array $params = []): void { $apiVersion = $this->getApiVersionSupport(); $picoDeprecated = $this->getPicoDeprecated(); diff --git a/lib/PluginApiPluginInterface.php b/lib/PluginApiPluginInterface.php index 1346f21..f2f9787 100644 --- a/lib/PluginApiPluginInterface.php +++ b/lib/PluginApiPluginInterface.php @@ -10,6 +10,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated; /** @@ -28,12 +30,12 @@ interface PluginApiPluginInterface extends PluginInterface * @param string $eventName name of the triggered event * @param array $params passed parameters */ - public function handleCustomEvent($eventName, array $params = []); + public function handleCustomEvent(string $eventName, array $params = []): void; /** * Returns the API version this plugin maintains backward compatibility for * * @return int */ - public function getApiVersionSupport(); + public function getApiVersionSupport(): int; } diff --git a/lib/PluginInterface.php b/lib/PluginInterface.php index c7f431c..cdf751b 100644 --- a/lib/PluginInterface.php +++ b/lib/PluginInterface.php @@ -10,6 +10,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated; use Pico; @@ -31,14 +33,14 @@ interface PluginInterface * @param string $eventName name of the triggered event * @param array $params passed parameters */ - public function handleEvent($eventName, array $params); + public function handleEvent(string $eventName, array $params): void; /** * Returns a list of names of compat plugins required by this plugin * * @return string[] required plugins */ - public function getDependencies(); + public function getDependencies(): array; /** * Returns the plugin's instance of Pico @@ -47,7 +49,7 @@ public function getDependencies(); * * @return Pico the plugin's instance of Pico */ - public function getPico(); + public function getPico(): Pico; /** * Returns the plugin's main PicoDeprecated plugin instance @@ -56,12 +58,12 @@ public function getPico(); * * @return PicoDeprecated the plugin's instance of Pico */ - public function getPicoDeprecated(); + public function getPicoDeprecated(): PicoDeprecated; /** * Returns the version of the API this plugin uses * * @return int the API version used by this plugin */ - public function getApiVersion(); + public function getApiVersion(): int; } diff --git a/plugins/MainPlugin.php b/plugins/MainPlugin.php index 41391f8..8382d8e 100644 --- a/plugins/MainPlugin.php +++ b/plugins/MainPlugin.php @@ -18,6 +18,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated\Plugin; use picocms\PicoDeprecated\AbstractPlugin; @@ -45,7 +47,7 @@ class MainPlugin extends AbstractPlugin * * @param object[] $plugins loaded plugin instances */ - public function onPluginsLoaded(array $plugins) + public function onPluginsLoaded(array $plugins): void { // deprecated since Pico 1.0 if (is_file($this->getPico()->getRootDir() . 'config.php')) { @@ -72,7 +74,7 @@ public function onPluginsLoaded(array $plugins) * * @param string $configFile path to the config file to load */ - protected function loadScriptedConfig($configFile) + protected function loadScriptedConfig(string $configFile): void { // scope isolated require() $includeConfigClosure = function ($configFile) { @@ -100,7 +102,7 @@ protected function loadScriptedConfig($configFile) /** * {@inheritDoc} */ - public function getApiVersion() + public function getApiVersion(): int { return PicoDeprecated::API_VERSION_3; } diff --git a/plugins/PluginApi0Plugin.php b/plugins/PluginApi0Plugin.php index 7145c90..76a13df 100644 --- a/plugins/PluginApi0Plugin.php +++ b/plugins/PluginApi0Plugin.php @@ -18,6 +18,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated\Plugin; use picocms\PicoDeprecated\AbstractPluginApiPlugin; @@ -77,7 +79,7 @@ class PluginApi0Plugin extends AbstractPluginApiPlugin * * @param object[] $plugins loaded plugin instances */ - public function onPluginsLoaded(array &$plugins) + public function onPluginsLoaded(array &$plugins): void { $this->triggerEvent('plugins_loaded'); } @@ -92,7 +94,7 @@ public function onPluginsLoaded(array &$plugins) * * @param array &$config array of config variables */ - public function onConfigLoaded(array &$config) + public function onConfigLoaded(array &$config): void { $this->defineConfigConstants($config); @@ -111,7 +113,7 @@ public function onConfigLoaded(array &$config) * * @param array &$config array of config variables */ - protected function defineConfigConstants(array &$config) + protected function defineConfigConstants(array &$config): void { if (!defined('ROOT_DIR')) { define('ROOT_DIR', $this->getPico()->getRootDir()); @@ -148,7 +150,7 @@ protected function defineConfigConstants(array &$config) * * @param string &$file absolute path to the content file to serve */ - public function onRequestFile(&$file) + public function onRequestFile(string &$file): void { $this->requestFile = &$file; } @@ -158,7 +160,7 @@ public function onRequestFile(&$file) * * @param string &$rawContent raw file contents */ - public function on404ContentLoaded(&$rawContent) + public function on404ContentLoaded(string &$rawContent): void { $this->triggerEvent('after_404_load_content', [ &$this->requestFile, &$rawContent ]); } @@ -168,7 +170,7 @@ public function on404ContentLoaded(&$rawContent) * * @param string &$rawContent raw file contents */ - public function onContentLoaded(&$rawContent) + public function onContentLoaded(string &$rawContent): void { $this->triggerEvent('after_load_content', [ &$this->requestFile, &$rawContent ]); } @@ -179,7 +181,7 @@ public function onContentLoaded(&$rawContent) * @param string &$rawContent raw file contents * @param string[] &$headers list of known meta header fields */ - public function onMetaParsing(&$rawContent, array &$headers) + public function onMetaParsing(string &$rawContent, array &$headers): void { $this->triggerEvent('before_read_file_meta', [ &$headers ]); } @@ -189,7 +191,7 @@ public function onMetaParsing(&$rawContent, array &$headers) * * @param array &$pageData data of the loaded page */ - public function onSinglePageLoaded(array &$pageData) + public function onSinglePageLoaded(array &$pageData): void { $this->triggerEvent('get_page_data', [ &$pageData, $pageData['meta'] ]); } @@ -213,7 +215,7 @@ public function onPagesLoaded( array &$currentPage = null, array &$previousPage = null, array &$nextPage = null - ) { + ): void { // remove keys of pages array $plainPages = []; foreach ($pages as &$plainPageData) { @@ -263,7 +265,7 @@ public function onPagesLoaded( * @param string &$templateName file name of the template * @param array &$twigVariables template variables */ - public function onPageRendering(TwigEnvironment &$twig, array &$twigVariables, &$templateName) + public function onPageRendering(TwigEnvironment &$twig, array &$twigVariables, string &$templateName): void { $templateNameInfo = pathinfo($templateName) + [ 'extension' => '' ]; @@ -280,7 +282,7 @@ public function onPageRendering(TwigEnvironment &$twig, array &$twigVariables, & /** * {@inheritDoc} */ - public function handleCustomEvent($eventName, array $params = []) + public function handleCustomEvent(string $eventName, array $params = []): void { // never trigger custom events } @@ -288,7 +290,7 @@ public function handleCustomEvent($eventName, array $params = []) /** * {@inheritDoc} */ - public function triggerEvent($eventName, array $params = []) + public function triggerEvent(string $eventName, array $params = []): void { // we don't support compat plugins using API v0, so no need to take care of compat plugins here // API v0 events are also triggered on plugins using API v1 (but not later) @@ -305,7 +307,7 @@ public function triggerEvent($eventName, array $params = []) /** * {@inheritDoc} */ - public function getApiVersion() + public function getApiVersion(): int { return PicoDeprecated::API_VERSION_1; } @@ -313,7 +315,7 @@ public function getApiVersion() /** * {@inheritDoc} */ - public function getApiVersionSupport() + public function getApiVersionSupport(): int { return PicoDeprecated::API_VERSION_0; } diff --git a/plugins/PluginApi1Plugin.php b/plugins/PluginApi1Plugin.php index 581de4b..2ea7233 100644 --- a/plugins/PluginApi1Plugin.php +++ b/plugins/PluginApi1Plugin.php @@ -18,6 +18,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated\Plugin; use picocms\PicoDeprecated\AbstractPluginApiPlugin; @@ -123,7 +125,7 @@ class PluginApi1Plugin extends AbstractPluginApiPlugin * * @param object[] $plugins loaded plugin instances */ - public function onPluginsLoaded(array $plugins) + public function onPluginsLoaded(array $plugins): void { $originalPlugins = $plugins; @@ -158,7 +160,7 @@ public function onPluginsLoaded(array $plugins) * * @param string &$file absolute path to the content file to serve */ - public function onRequestFile(&$file) + public function onRequestFile(string &$file): void { $this->requestFile = &$file; } @@ -166,7 +168,7 @@ public function onRequestFile(&$file) /** * Triggers the onContentLoading event */ - public function onContentLoading() + public function onContentLoading(): void { $this->triggerEvent('onContentLoading', [ &$this->requestFile ]); } @@ -178,7 +180,7 @@ public function onContentLoading() * * @param string &$rawContent raw file contents */ - public function onContentLoaded(&$rawContent) + public function onContentLoaded(string &$rawContent): void { $this->rawContent = &$rawContent; } @@ -186,7 +188,7 @@ public function onContentLoaded(&$rawContent) /** * Triggers the on404ContentLoading event */ - public function on404ContentLoading() + public function on404ContentLoading(): void { $this->triggerEvent('on404ContentLoading', [ &$this->requestFile ]); } @@ -196,7 +198,7 @@ public function on404ContentLoading() * * @see PluginApi1Plugin::onMetaHeaders() */ - public function onMetaParsing() + public function onMetaParsing(): void { $headersFlipped = $this->getFlippedMetaHeaders(); $this->triggerEvent('onMetaParsing', [ &$this->rawContent, &$headersFlipped ]); @@ -208,7 +210,7 @@ public function onMetaParsing() * * @param string[] &$meta parsed meta data */ - public function onMetaParsed(array &$meta) + public function onMetaParsed(array &$meta): void { $this->triggerEvent('onMetaParsed', [ &$meta ]); $this->triggerEvent('onParsedownRegistration'); @@ -217,7 +219,7 @@ public function onMetaParsed(array &$meta) /** * Triggers the onContentParsing event */ - public function onContentParsing() + public function onContentParsing(): void { $this->triggerEvent('onContentParsing', [ &$this->rawContent ]); } @@ -229,7 +231,7 @@ public function onContentParsing() * * @param array[] &$pages sorted list of all known pages */ - public function onPagesLoaded(array &$pages) + public function onPagesLoaded(array &$pages): void { $this->pages = &$pages; } @@ -245,7 +247,7 @@ public function onCurrentPageDiscovered( array &$currentPage = null, array &$previousPage = null, array &$nextPage = null - ) { + ): void { $this->triggerEvent('onPagesLoaded', [ &$this->pages, &$currentPage, &$previousPage, &$nextPage ]); $this->triggerEvent('onTwigRegistration'); @@ -258,7 +260,7 @@ public function onCurrentPageDiscovered( * @param string &$templateName file name of the template * @param array &$twigVariables template variables */ - public function onPageRendering(&$templateName, array &$twigVariables) + public function onPageRendering(string &$templateName, array &$twigVariables): void { $this->triggerEvent('onPageRendering', [ &$this->twig, &$twigVariables, &$templateName ]); } @@ -273,7 +275,7 @@ public function onPageRendering(&$templateName, array &$twigVariables) * key specifies the YAML key to search for, the array value is later * used to access the found value */ - public function onMetaHeaders(array &$headers) + public function onMetaHeaders(array &$headers): void { $this->metaHeaders = &$headers; @@ -289,7 +291,7 @@ public function onMetaHeaders(array &$headers) * * @param TwigEnvironment &$twig Twig instance */ - public function onTwigRegistered(TwigEnvironment &$twig) + public function onTwigRegistered(TwigEnvironment &$twig): void { $this->twig = $twig; } @@ -306,7 +308,7 @@ public function onTwigRegistered(TwigEnvironment &$twig) * * @return array flipped meta headers */ - protected function getFlippedMetaHeaders() + protected function getFlippedMetaHeaders(): array { if ($this->metaHeaders === null) { // make sure to trigger the onMetaHeaders event @@ -321,7 +323,7 @@ protected function getFlippedMetaHeaders() * * @param array $headersFlipped flipped headers array */ - protected function updateFlippedMetaHeaders(array $headersFlipped) + protected function updateFlippedMetaHeaders(array $headersFlipped): void { foreach ($this->metaHeaders as $name => $key) { if (!isset($headersFlipped[$key])) { @@ -337,7 +339,7 @@ protected function updateFlippedMetaHeaders(array $headersFlipped) /** * {@inheritDoc} */ - public function getApiVersion() + public function getApiVersion(): int { return PicoDeprecated::API_VERSION_2; } @@ -345,7 +347,7 @@ public function getApiVersion() /** * {@inheritDoc} */ - public function getApiVersionSupport() + public function getApiVersionSupport(): int { return PicoDeprecated::API_VERSION_1; } diff --git a/plugins/PluginApi2Plugin.php b/plugins/PluginApi2Plugin.php index c98982c..6a7fcff 100644 --- a/plugins/PluginApi2Plugin.php +++ b/plugins/PluginApi2Plugin.php @@ -18,6 +18,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated\Plugin; use picocms\PicoDeprecated\AbstractPluginApiPlugin; @@ -95,7 +97,7 @@ class PluginApi2Plugin extends AbstractPluginApiPlugin * * @param array $config */ - public function onConfigLoaded(array &$config) + public function onConfigLoaded(array &$config): void { $this->config = &$config; @@ -112,7 +114,7 @@ public function onConfigLoaded(array &$config) * @param int $themeApiVersion API version of the theme * @param array &$themeConfig config array of the theme */ - public function onThemeLoaded($theme, $themeApiVersion, array &$themeConfig) + public function onThemeLoaded(string $theme, int $themeApiVersion, array &$themeConfig): void { $this->triggerEvent('onConfigLoaded', [ &$this->config ]); } @@ -120,7 +122,7 @@ public function onThemeLoaded($theme, $themeApiVersion, array &$themeConfig) /** * {@inheritDoc} */ - public function getApiVersion() + public function getApiVersion(): int { return PicoDeprecated::API_VERSION_3; } @@ -128,7 +130,7 @@ public function getApiVersion() /** * {@inheritDoc} */ - public function getApiVersionSupport() + public function getApiVersionSupport(): int { return PicoDeprecated::API_VERSION_2; } diff --git a/plugins/PluginApi3Plugin.php b/plugins/PluginApi3Plugin.php index d52a459..d8b77a3 100644 --- a/plugins/PluginApi3Plugin.php +++ b/plugins/PluginApi3Plugin.php @@ -10,6 +10,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated\Plugin; use picocms\PicoDeprecated\AbstractPluginApiPlugin; @@ -76,7 +78,7 @@ class PluginApi3Plugin extends AbstractPluginApiPlugin /** * {@inheritDoc} */ - public function getApiVersion() + public function getApiVersion(): int { return PicoDeprecated::API_VERSION_4; } @@ -84,7 +86,7 @@ public function getApiVersion() /** * {@inheritDoc} */ - public function getApiVersionSupport() + public function getApiVersionSupport(): int { return PicoDeprecated::API_VERSION_3; } diff --git a/plugins/ThemeApi0Plugin.php b/plugins/ThemeApi0Plugin.php index c823d45..b378c17 100644 --- a/plugins/ThemeApi0Plugin.php +++ b/plugins/ThemeApi0Plugin.php @@ -18,6 +18,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated\Plugin; use picocms\PicoDeprecated\AbstractPlugin; @@ -50,7 +52,7 @@ class ThemeApi0Plugin extends AbstractPlugin /** * {@inheritDoc} */ - public function getApiVersion() + public function getApiVersion(): int { return PicoDeprecated::API_VERSION_3; } diff --git a/plugins/ThemeApi1Plugin.php b/plugins/ThemeApi1Plugin.php index ecfec8a..2a5c588 100644 --- a/plugins/ThemeApi1Plugin.php +++ b/plugins/ThemeApi1Plugin.php @@ -18,6 +18,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated\Plugin; use picocms\PicoDeprecated\AbstractPlugin; @@ -49,7 +51,7 @@ class ThemeApi1Plugin extends AbstractPlugin * * @param string[] &$meta parsed meta data */ - public function onMetaParsed(array &$meta) + public function onMetaParsed(array &$meta): void { $this->lowerFileMeta($meta); } @@ -61,7 +63,7 @@ public function onMetaParsed(array &$meta) * * @param array &$pageData data of the loaded page */ - public function onSinglePageLoaded(array &$pageData) + public function onSinglePageLoaded(array &$pageData): void { // don't lower the file meta of the requested page, // it was already lowered during the onMetaParsed event @@ -79,7 +81,7 @@ public function onSinglePageLoaded(array &$pageData) * @param string &$templateName file name of the template * @param array &$twigVariables template variables */ - public function onPageRendering(&$templateName, array &$twigVariables) + public function onPageRendering(string &$templateName, array &$twigVariables): void { if (!isset($twigVariables['rewrite_url'])) { $twigVariables['rewrite_url'] = $this->getPico()->isUrlRewritingEnabled(); @@ -121,7 +123,7 @@ public function onPageRendering(&$templateName, array &$twigVariables) * * @param array &$meta meta data */ - protected function lowerFileMeta(array &$meta) + protected function lowerFileMeta(array &$meta): void { $metaHeaders = $this->getPico()->getMetaHeaders(); @@ -153,7 +155,7 @@ protected function lowerFileMeta(array &$meta) /** * {@inheritDoc} */ - public function getApiVersion() + public function getApiVersion(): int { return PicoDeprecated::API_VERSION_3; } diff --git a/plugins/ThemeApi2Plugin.php b/plugins/ThemeApi2Plugin.php index ec8723f..3abb9ab 100644 --- a/plugins/ThemeApi2Plugin.php +++ b/plugins/ThemeApi2Plugin.php @@ -18,6 +18,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated\Plugin; use picocms\PicoDeprecated\AbstractPlugin; @@ -59,7 +61,7 @@ class ThemeApi2Plugin extends AbstractPlugin * * @param array &$config array of config variables */ - public function onConfigLoaded(array &$config) + public function onConfigLoaded(array &$config): void { if (isset($config['twig_config']['autoescape'])) { $this->twigEscapeStrategy = $config['twig_config']['autoescape']; @@ -72,7 +74,7 @@ public function onConfigLoaded(array &$config) * @param string &$templateName file name of the template * @param array &$twigVariables template variables */ - public function onPageRendering(&$templateName, array &$twigVariables) + public function onPageRendering(string &$templateName, array &$twigVariables): void { $twigVariables['prev_page'] = &$twigVariables['previous_page']; $twigVariables['base_dir'] = rtrim($this->getPico()->getRootDir(), '/'); @@ -87,7 +89,7 @@ public function onPageRendering(&$templateName, array &$twigVariables) * * @param TwigEnvironment &$twig Twig instance */ - public function onTwigRegistered(TwigEnvironment &$twig) + public function onTwigRegistered(TwigEnvironment &$twig): void { if ($twig->hasExtension(TwigEscaperExtension::class)) { /** @var TwigEscaperExtension $escaperExtension */ @@ -110,7 +112,7 @@ public function onTwigRegistered(TwigEnvironment &$twig) * * @return string|false escape strategy for this template */ - public function twigEscapeStrategy($templateName) + public function twigEscapeStrategy(string $templateName) { $twigConfig = $this->getPico()->getConfig('twig_config'); $escapeStrategy = $twigConfig['autoescape']; @@ -163,7 +165,7 @@ public function twigEscapeStrategy($templateName) * * @return object|null either the matching plugin instance or NULL */ - protected function getPluginFromPath($path) + protected function getPluginFromPath(string $path): ?object { $plugins = $this->getPico()->getPlugins(); foreach ($this->pluginPaths as $pluginName => $pluginPath) { @@ -201,7 +203,7 @@ protected function getPluginFromPath($path) /** * {@inheritDoc} */ - public function getApiVersion() + public function getApiVersion(): int { return PicoDeprecated::API_VERSION_3; } diff --git a/plugins/ThemeApi3Plugin.php b/plugins/ThemeApi3Plugin.php index 3589a49..8a84259 100644 --- a/plugins/ThemeApi3Plugin.php +++ b/plugins/ThemeApi3Plugin.php @@ -10,6 +10,8 @@ * License-Filename: LICENSE */ +declare(strict_types=1); + namespace picocms\PicoDeprecated\Plugin; use picocms\PicoDeprecated\AbstractPlugin; @@ -29,7 +31,7 @@ class ThemeApi3Plugin extends AbstractPlugin /** * {@inheritDoc} */ - public function getApiVersion() + public function getApiVersion(): int { return PicoDeprecated::API_VERSION_4; } From 54e5230eac33bd30ae46ce3a4d3bd10abf1a1da4 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 8 Mar 2022 23:35:30 +0100 Subject: [PATCH 20/28] Various small improvements --- PicoDeprecated.php | 18 +++++++++++------- plugins/MainPlugin.php | 10 ++++------ plugins/PluginApi0Plugin.php | 5 +++-- plugins/PluginApi1Plugin.php | 5 +++-- plugins/PluginApi2Plugin.php | 2 +- plugins/ThemeApi1Plugin.php | 3 +-- plugins/ThemeApi2Plugin.php | 10 +++++++++- 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/PicoDeprecated.php b/PicoDeprecated.php index 570cd8b..6c00145 100644 --- a/PicoDeprecated.php +++ b/PicoDeprecated.php @@ -104,7 +104,7 @@ class PicoDeprecated extends AbstractPicoPlugin * * @see PicoDeprecated::getPlugins() * - * @var object[] + * @var object[][] */ protected $plugins = []; @@ -137,9 +137,9 @@ public function __construct(Pico $pico) ); } - if ($pico::API_VERSION !== static::API_VERSION) { + if ($pico::API_VERSION !== self::API_VERSION) { throw new RuntimeException( - 'PicoDeprecated requires API version ' . static::API_VERSION . ', ' + 'PicoDeprecated requires API version ' . self::API_VERSION . ', ' . 'but Pico is running API version ' . $pico::API_VERSION ); } @@ -157,7 +157,7 @@ public function handleEvent($eventName, array $params) $isCoreEvent = in_array($eventName, $this->getCoreEvents()); foreach ($this->compatPlugins as $plugin) { if ($isCoreEvent) { - if ($plugin->getApiVersion() === static::API_VERSION) { + if ($plugin->getApiVersion() === self::API_VERSION) { $plugin->handleEvent($eventName, $params); } } elseif ($plugin instanceof PluginApiPluginInterface) { @@ -242,7 +242,7 @@ protected function loadPlugin(object $plugin): void */ public function getPlugins(int $apiVersion): array { - return isset($this->plugins[$apiVersion]) ? $this->plugins[$apiVersion] : []; + return $this->plugins[$apiVersion] ?? []; } /** @@ -257,6 +257,10 @@ public function loadCompatPlugin($plugin): PluginInterface { if (!is_object($plugin)) { $className = (string) $plugin; + if (isset($this->compatPlugins[$className])) { + return $this->compatPlugins[$className]; + } + if (class_exists($className)) { $plugin = new $className($this->getPico(), $this); } else { @@ -298,7 +302,7 @@ public function loadCompatPlugin($plugin): PluginInterface */ protected function loadPluginApiCompatPlugin(int $apiVersion): void { - if ($apiVersion !== static::API_VERSION) { + if ($apiVersion !== self::API_VERSION) { $this->loadCompatPlugin('picocms\PicoDeprecated\Plugin\PluginApi' . $apiVersion . 'Plugin'); } } @@ -310,7 +314,7 @@ protected function loadPluginApiCompatPlugin(int $apiVersion): void */ protected function loadThemeApiCompatPlugin(int $apiVersion): void { - if ($apiVersion !== static::API_VERSION) { + if ($apiVersion !== self::API_VERSION) { $this->loadCompatPlugin('picocms\PicoDeprecated\Plugin\ThemeApi' . $apiVersion . 'Plugin'); } } diff --git a/plugins/MainPlugin.php b/plugins/MainPlugin.php index 8382d8e..2919950 100644 --- a/plugins/MainPlugin.php +++ b/plugins/MainPlugin.php @@ -24,6 +24,7 @@ use picocms\PicoDeprecated\AbstractPlugin; use PicoDeprecated; +use ReflectionObject; /** * Maintains backward compatibility with older Pico versions @@ -77,18 +78,15 @@ public function onPluginsLoaded(array $plugins): void protected function loadScriptedConfig(string $configFile): void { // scope isolated require() - $includeConfigClosure = function ($configFile) { + $includeConfigClosure = static function ($configFile) { require($configFile); return (isset($config) && is_array($config)) ? $config : []; }; - if (PHP_VERSION_ID >= 50400) { - $includeConfigClosure = $includeConfigClosure->bindTo(null); - } $scriptedConfig = $includeConfigClosure($configFile); if (!empty($scriptedConfig)) { - $picoReflector = new \ReflectionObject($this->getPico()); + $picoReflector = new ReflectionObject($this->getPico()); $picoConfigReflector = $picoReflector->getProperty('config'); $picoConfigReflector->setAccessible(true); @@ -104,6 +102,6 @@ protected function loadScriptedConfig(string $configFile): void */ public function getApiVersion(): int { - return PicoDeprecated::API_VERSION_3; + return PicoDeprecated::API_VERSION_4; } } diff --git a/plugins/PluginApi0Plugin.php b/plugins/PluginApi0Plugin.php index 76a13df..9622795 100644 --- a/plugins/PluginApi0Plugin.php +++ b/plugins/PluginApi0Plugin.php @@ -25,6 +25,7 @@ use picocms\PicoDeprecated\AbstractPluginApiPlugin; use Pico; use PicoDeprecated; +use ReflectionClass; use Twig\Environment as TwigEnvironment; /** @@ -122,7 +123,7 @@ protected function defineConfigConstants(array &$config): void define('CONFIG_DIR', $this->getPico()->getConfigDir()); } if (!defined('LIB_DIR')) { - $picoReflector = new \ReflectionClass(Pico::class); + $picoReflector = new ReflectionClass(Pico::class); define('LIB_DIR', dirname($picoReflector->getFileName()) . '/'); } if (!defined('PLUGINS_DIR')) { @@ -262,8 +263,8 @@ public function onPagesLoaded( * without its file extension. The file extension is re-added later. * * @param TwigEnvironment &$twig Twig instance - * @param string &$templateName file name of the template * @param array &$twigVariables template variables + * @param string &$templateName file name of the template */ public function onPageRendering(TwigEnvironment &$twig, array &$twigVariables, string &$templateName): void { diff --git a/plugins/PluginApi1Plugin.php b/plugins/PluginApi1Plugin.php index 2ea7233..0bdab13 100644 --- a/plugins/PluginApi1Plugin.php +++ b/plugins/PluginApi1Plugin.php @@ -24,6 +24,7 @@ use picocms\PicoDeprecated\AbstractPluginApiPlugin; use PicoDeprecated; +use RuntimeException; use Twig\Environment as TwigEnvironment; /** @@ -135,7 +136,7 @@ public function onPluginsLoaded(array $plugins): void if (!isset($originalPlugins[$pluginName])) { $this->getPico()->loadPlugin($plugin); } elseif ($plugin !== $originalPlugins[$pluginName]) { - throw new \RuntimeException( + throw new RuntimeException( "A Pico plugin using API version 1 tried to replace Pico plugin '" . $pluginName . "' using the " . "onPluginsLoaded() event, however, replacing plugins was removed with API version 2" ); @@ -146,7 +147,7 @@ public function onPluginsLoaded(array $plugins): void if ($originalPlugins) { $removedPluginsList = implode("', '", array_keys($originalPlugins)); - throw new \RuntimeException( + throw new RuntimeException( "A Pico plugin using API version 1 tried to unload the Pico plugin(s) '" . $removedPluginsList . "' " . "using the onPluginsLoaded() event, however, unloading plugins was removed with API version 2" ); diff --git a/plugins/PluginApi2Plugin.php b/plugins/PluginApi2Plugin.php index 6a7fcff..84ba0b7 100644 --- a/plugins/PluginApi2Plugin.php +++ b/plugins/PluginApi2Plugin.php @@ -41,7 +41,7 @@ class PluginApi2Plugin extends AbstractPluginApiPlugin * * @var string[] */ - protected $dependsOn = [ ThemeApi2Plugin::class ]; + protected $dependsOn = [ PluginApi3Plugin::class, ThemeApi2Plugin::class ]; /** * Map of core events matching event signatures of older API versions diff --git a/plugins/ThemeApi1Plugin.php b/plugins/ThemeApi1Plugin.php index 2a5c588..2db9a8f 100644 --- a/plugins/ThemeApi1Plugin.php +++ b/plugins/ThemeApi1Plugin.php @@ -75,7 +75,7 @@ public function onSinglePageLoaded(array &$pageData): void } /** - * Handles .html Twig templates and re-introcudes the Twig variables + * Handles .html Twig templates and re-introduces the Twig variables * rewrite_url and is_front_page * * @param string &$templateName file name of the template @@ -107,7 +107,6 @@ public function onPageRendering(string &$templateName, array &$twigVariables): v $twig->loadTemplate($templateNameInfo['filename'] . '.html'); $templateName = $templateNameInfo['filename'] . '.html'; - $templateNameInfo['extension'] = 'html'; } catch (TwigLoaderError $e) { // template doesn't exist, Twig will very likely fail later } diff --git a/plugins/ThemeApi2Plugin.php b/plugins/ThemeApi2Plugin.php index 3abb9ab..d100921 100644 --- a/plugins/ThemeApi2Plugin.php +++ b/plugins/ThemeApi2Plugin.php @@ -24,6 +24,7 @@ use picocms\PicoDeprecated\AbstractPlugin; use PicoDeprecated; +use ReflectionObject; use Twig\Environment as TwigEnvironment; use Twig\Error\LoaderError as TwigLoaderError; use Twig\Extension\EscaperExtension as TwigEscaperExtension; @@ -40,6 +41,13 @@ */ class ThemeApi2Plugin extends AbstractPlugin { + /** + * This plugin extends {@see ThemeApi3Plugin} + * + * @var string[] + */ + protected $dependsOn = [ ThemeApi3Plugin::class ]; + /** * Manually configured Twig escape strategy * @@ -183,7 +191,7 @@ protected function getPluginFromPath(string $path): ?object continue; } - $pluginReflector = new \ReflectionObject($plugin); + $pluginReflector = new ReflectionObject($plugin); $pluginPath = dirname($pluginReflector->getFileName() ?: '') . '/'; if (in_array($pluginPath, [ '/', $rootDir, $vendorDir, $pluginsDir, $themesDir ], true)) { From 1206105b607356e2a324ab375c7679354c04e8b7 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 8 Mar 2022 23:38:51 +0100 Subject: [PATCH 21/28] ThemeApi1Plugin::onPageRendering(): Fix usage of TwigEnvironment::load() --- plugins/ThemeApi1Plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/ThemeApi1Plugin.php b/plugins/ThemeApi1Plugin.php index 2db9a8f..ee17208 100644 --- a/plugins/ThemeApi1Plugin.php +++ b/plugins/ThemeApi1Plugin.php @@ -100,11 +100,11 @@ public function onPageRendering(string &$templateName, array &$twigVariables): v $twig = $this->getPico()->getTwig(); try { - $twig->loadTemplate($templateName); + $twig->load($templateName); } catch (TwigLoaderError $e) { if ($templateNameInfo['extension'] === 'twig') { try { - $twig->loadTemplate($templateNameInfo['filename'] . '.html'); + $twig->load($templateNameInfo['filename'] . '.html'); $templateName = $templateNameInfo['filename'] . '.html'; } catch (TwigLoaderError $e) { From 06b0a539f297e1f362d0eefa1796684a4efdf776 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 13 Mar 2022 12:17:48 +0100 Subject: [PATCH 22/28] Update CHANGELOG.md --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abfdc7b..9ec2a00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,23 @@ Pico Deprecated Changelog because they are already listed in Pico's changelog. Only functional changes and/or BC-breaking changes are listed below. +### Version 3.0.0-beta.1 +Released: - + +``` +* [New] Update to API version 4 (no functional changes necessary) +* [New] Add new continous integration (CI) pipeline using GitHub Actions +* [New] Add new build script and Makefile to simplify PicoDeprecated's build + and release process; see Pico's `CONTRIBUTING.md` for details +* [New] Add `PicoDeprecated::VERSION` and `PicoDeprecated::VERSION_ID` + constants (similar to Pico's matching constants) +* [New] Add plugin and theme compatibility plugin for API version 3 +* [Changed] Enable PHP strict typing +* [Changed] ! Move classes to `\picocms\PicoDeprecated\…` PHP namespace +* [Fixed] Don't instantiate compatibility plugins multiple times +* [Fixed] Update Twig API usage to be compatible with Twig 3.3 +``` + ### Version 3.0.0-alpha.2 Released: 2020-12-24 From 5f5f2fa93989dd13e96626e4103165617b9977b4 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 15 Mar 2022 20:30:54 +0100 Subject: [PATCH 23/28] Add version check to PicoDeprecated constructor --- PicoDeprecated.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/PicoDeprecated.php b/PicoDeprecated.php index 6c00145..fea86a9 100644 --- a/PicoDeprecated.php +++ b/PicoDeprecated.php @@ -129,11 +129,17 @@ public function __construct(Pico $pico) } if (!class_exists(MainPlugin::class)) { - die( - "Cannot find PicoDeprecated's 'vendor/autoload.php'. If you're using a composer-based Pico install, " + throw new RuntimeException( + "Cannot find PicoDeprecated's 'vendor/autoload.php'. If you're using a Composer-based Pico install, " . "run `composer update`. If you're rather trying to use one of PicoDeprecated's pre-built release " . "packages, make sure to download PicoDeprecated's release package matching Pico's version named " - . "'pico-deprecated-release-v*.tar.gz' (don't download a source code package)." + . "'pico-deprecated-release-v*.tar.gz'; make sure not to download a source code package." + ); + } + + if ($pico::VERSION_ID !== self::VERSION_ID) { + throw new RuntimeException( + 'PicoDeprecated v' . self::VERSION . ' is incompatible with Pico v' . $pico::VERSION ); } From ccf11948cf8a7bfb42d4516f0f8b07b6bcfeb1fd Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 15 Mar 2022 20:32:00 +0100 Subject: [PATCH 24/28] CI: Restore picocms/Pico dependency in build script Requires Composer 2.2.8 or later --- .build/build.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.build/build.sh b/.build/build.sh index 8818a31..665bd47 100755 --- a/.build/build.sh +++ b/.build/build.sh @@ -273,10 +273,9 @@ find vendor/ -type d -path 'vendor/*/*/.git' -print0 | xargs -0 rm -rf echo # restore picocms/pico dependency -# FIXME: https://github.com/composer/composer/issues/10593 -#echo "Restoring '$PICO_PROJECT' dependency..." -#"$COMPOSER" require --no-update "$PICO_PROJECT self.version" -#echo +echo "Restoring '$PICO_PROJECT' dependency..." +"$COMPOSER" require --no-update "$PICO_PROJECT self.version" +echo # create release archives ARCHIVE_FILENAME="$BUILD_NAME-release-$VERSION" From b138d5deeae9c614bdebde329472afa4810b2d8f Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 5 Jan 2023 22:53:49 +0100 Subject: [PATCH 25/28] PluginApi3Plugin doesn't necessarily depend on ThemeApi3Plugin --- plugins/PluginApi3Plugin.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/plugins/PluginApi3Plugin.php b/plugins/PluginApi3Plugin.php index d8b77a3..df5a3e5 100644 --- a/plugins/PluginApi3Plugin.php +++ b/plugins/PluginApi3Plugin.php @@ -28,13 +28,6 @@ */ class PluginApi3Plugin extends AbstractPluginApiPlugin { - /** - * This plugin extends {@see ThemeApi3Plugin} - * - * @var string[] - */ - protected $dependsOn = [ ThemeApi3Plugin::class ]; - /** * Map of core events matching event signatures of older API versions * From 65336388615bc52128b79b212ac31d81bdb0ac33 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 5 Jan 2023 22:54:15 +0100 Subject: [PATCH 26/28] Various small improvements --- .build/build.sh | 4 ++-- plugins/ThemeApi2Plugin.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.build/build.sh b/.build/build.sh index 665bd47..b926661 100755 --- a/.build/build.sh +++ b/.build/build.sh @@ -287,10 +287,10 @@ find . -mindepth 1 -maxdepth 1 -printf '%f\0' \ echo "Creating release archive '$ARCHIVE_FILENAME.zip'..." zip -q -r "$APP_DIR/$ARCHIVE_FILENAME.zip" . -echo - # publish release if [ -n "$PUBLISH" ]; then + echo + # switch to app dir cd "$APP_DIR" diff --git a/plugins/ThemeApi2Plugin.php b/plugins/ThemeApi2Plugin.php index d100921..73de6c8 100644 --- a/plugins/ThemeApi2Plugin.php +++ b/plugins/ThemeApi2Plugin.php @@ -90,10 +90,10 @@ public function onPageRendering(string &$templateName, array &$twigVariables): v } /** - * Registers PluginApi2Plugin::twigEscapeStrategy() as Twig's default + * Registers ThemeApi2Plugin::twigEscapeStrategy() as Twig's default * escape strategy * - * @see PluginApi2Plugin::twigEscapeStrategy() + * @see ThemeApi2Plugin::twigEscapeStrategy() * * @param TwigEnvironment &$twig Twig instance */ From 38c788d2abda63cb83028053108caa6ce085c01d Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Thu, 5 Jan 2023 22:57:50 +0100 Subject: [PATCH 27/28] CI: Add bouncer step to PR testing --- .github/workflows/test-pr.yml | 27 +++++++++++++++++++++++++++ .github/workflows/test.yml | 1 - 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-pr.yml diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml new file mode 100644 index 0000000..c6fd342 --- /dev/null +++ b/.github/workflows/test-pr.yml @@ -0,0 +1,27 @@ +name: Test PicoDeprecated pull request + +on: + pull_request: {} + +jobs: + test: + name: Test PicoDeprecated + uses: ./.github/workflows/test.yml + + bouncer: + name: Bouncer + + needs: test + if: ${{ always() }} + + runs-on: ubuntu-latest + permissions: {} + + steps: + - name: Check build matrix status + if: ${{ needs.test.result != 'success' }} + run: | + : + echo "Some tests of PicoDeprecated failed." >&2 + echo "Please check the GitHub workflow logs for details." >&2 + exit 1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2c7030..b01777e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,6 @@ on: - 'master' - 'pico-3.0' tags: [ 'v*.*.*' ] - pull_request: {} workflow_call: {} jobs: From 0edf3854590adb264635b61aa758968351a9e273 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Mon, 22 Dec 2025 17:49:05 +0100 Subject: [PATCH 28/28] Update CI workflows to test from PHP 7.2 to 8.5 --- .github/workflows/test.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b01777e..24b72f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,10 @@ jobs: - '7.4' - '8.0' - '8.1' + - '8.2' + - '8.3' + - '8.4' + - '8.5' - 'nightly' fail-fast: false @@ -34,7 +38,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v6 - name: Setup PHP ${{ env.PHP_VERSION }} uses: shivammathur/setup-php@v2 @@ -52,7 +56,7 @@ jobs: echo "COMPOSER_CACHE_DIR=$COMPOSER_CACHE_DIR" | tee -a "$GITHUB_ENV" - name: Restore Composer cache - uses: actions/cache@v2 + uses: actions/cache@v5 with: path: ${{ env.COMPOSER_CACHE_DIR }} key: ${{ runner.os }}-composer-php${{ env.PHP_VERSION }}