From 8325a5c6d5f402fcbbc458e2011dde9bc0d5c857 Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Mon, 3 Feb 2025 09:33:44 +0100 Subject: [PATCH 1/6] Require Twig 3.X and PHP >= 8.0 --- composer.json | 9 ++++++--- lib/clarkson-core-templates.php | 23 +++++++++++++++-------- lib/clarkson-core-twig-extension.php | 4 ++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index a8247ff..8e2524b 100644 --- a/composer.json +++ b/composer.json @@ -36,9 +36,12 @@ ] }, "require" : { - "twig/twig":"^1.2", - "twig/extensions":"^1.3", - "php":"^7.1|^8.0" + "twig/twig":"^3.19", + "php":">=8.0", + "twig/string-extra": "^3.19", + "twig/intl-extra": "^3.19", + "twig/html-extra": "^3.19", + "twig/markdown-extra": "^3.19" }, "require-dev": { "wp-coding-standards/wpcs": "^2.1", diff --git a/lib/clarkson-core-templates.php b/lib/clarkson-core-templates.php index fdb51f1..111f2fc 100644 --- a/lib/clarkson-core-templates.php +++ b/lib/clarkson-core-templates.php @@ -5,6 +5,12 @@ * @package CLARKSON\Lib */ +use Twig\Extension\DebugExtension; +use Twig\Extra\Html\HtmlExtension; +use Twig\Extra\Intl\IntlExtension; +use Twig\Extra\Markdown\MarkdownExtension; +use Twig\Extra\String\StringExtension; + /** * Allows rendering of specific templates with Twig. */ @@ -126,7 +132,7 @@ public function render_twig( $path, $objects, $ignore_warning = false ) { return $twig->render( $template_file, $context_args ); } - private function get_twig_environment( array $template_dirs ):Twig_Environment { + private function get_twig_environment( array $template_dirs ):\Twig\Environment { if ( ! $this->twig ) { $debug = ( defined( 'WP_DEBUG' ) ? constant( 'WP_DEBUG' ) : false ); $twig_args = array( @@ -150,17 +156,17 @@ private function get_twig_environment( array $template_dirs ):Twig_Environment { * } ); */ $twig_args = apply_filters( 'clarkson_twig_args', $twig_args ); - $twig_fs = new Twig_Loader_Filesystem( $template_dirs ); - $twig = new Twig_Environment( $twig_fs, $twig_args ); + $twig_fs = new \Twig\Loader\FilesystemLoader( $template_dirs ); + $twig = new \Twig\Environment( $twig_fs, $twig_args ); $twig->addExtension( new Clarkson_Core_Twig_Extension() ); - $twig->addExtension( new Twig_Extensions_Extension_I18n() ); - $twig->addExtension( new Twig_Extensions_Extension_Text() ); - $twig->addExtension( new Twig_Extensions_Extension_Array() ); - $twig->addExtension( new Twig_Extensions_Extension_Date() ); + $twig->addExtension( new IntlExtension() ); + $twig->addExtension( new StringExtension() ); + $twig->addExtension( new HtmlExtension() ); + $twig->addExtension( new MarkdownExtension() ); if ( $debug ) { - $twig->addExtension( new Twig_Extension_Debug() ); + $twig->addExtension( new DebugExtension() ); } /** @@ -180,6 +186,7 @@ private function get_twig_environment( array $template_dirs ):Twig_Environment { */ $this->twig = apply_filters( 'clarkson_twig_environment', $twig ); } + return $this->twig; } diff --git a/lib/clarkson-core-twig-extension.php b/lib/clarkson-core-twig-extension.php index d04aa2d..7496064 100644 --- a/lib/clarkson-core-twig-extension.php +++ b/lib/clarkson-core-twig-extension.php @@ -9,7 +9,7 @@ * Class Clarkson_Core_Twig_Extension. * @internal */ -class Clarkson_Core_Twig_Extension extends Twig_Extension { +class Clarkson_Core_Twig_Extension extends \Twig\Extension\AbstractExtension { /** * Twig functions. @@ -988,7 +988,7 @@ public function getFunctions() { $allowed_functions = apply_filters( 'clarkson_twig_functions', $this->functions ); foreach ( $allowed_functions as $function ) { - $twig_functions[] = new Twig_SimpleFunction( $function, $function ); + $twig_functions[] = new \Twig\TwigFunction( $function, $function ); } return $twig_functions; From e3813f74f59f89ee615dcb87acd7b9854260fa03 Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Mon, 3 Feb 2025 10:29:35 +0100 Subject: [PATCH 2/6] Fix clarkson core loader --- clarkson-core.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clarkson-core.php b/clarkson-core.php index b86c211..429c019 100644 --- a/clarkson-core.php +++ b/clarkson-core.php @@ -90,7 +90,9 @@ protected function __construct() { require_once $autoload_file; } - add_action( 'init', array( $this, 'init' ) ); + if ( is_callable( 'add_action' ) ) { + add_action( 'init', array( $this, 'init' ) ); + } if ( ! class_exists( 'Clarkson_Core_Autoloader' ) ) { return; @@ -116,7 +118,6 @@ protected function __construct() { $deprecated = Clarkson_Core_Deprecated::get_instance(); $deprecated->auto_load_theme(); } - } /** @@ -133,4 +134,4 @@ public function __wakeup() { } -add_action( 'plugins_loaded', array( 'Clarkson_Core', 'get_instance' ) ); +Clarkson_Core::get_instance(); From 3d306de588dddb8f589b66698fe0e0ea9f0debe1 Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Mon, 3 Feb 2025 11:12:15 +0100 Subject: [PATCH 3/6] Revert "Fix clarkson core loader" This reverts commit e3813f74f59f89ee615dcb87acd7b9854260fa03. --- clarkson-core.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/clarkson-core.php b/clarkson-core.php index 429c019..b86c211 100644 --- a/clarkson-core.php +++ b/clarkson-core.php @@ -90,9 +90,7 @@ protected function __construct() { require_once $autoload_file; } - if ( is_callable( 'add_action' ) ) { - add_action( 'init', array( $this, 'init' ) ); - } + add_action( 'init', array( $this, 'init' ) ); if ( ! class_exists( 'Clarkson_Core_Autoloader' ) ) { return; @@ -118,6 +116,7 @@ protected function __construct() { $deprecated = Clarkson_Core_Deprecated::get_instance(); $deprecated->auto_load_theme(); } + } /** @@ -134,4 +133,4 @@ public function __wakeup() { } -Clarkson_Core::get_instance(); +add_action( 'plugins_loaded', array( 'Clarkson_Core', 'get_instance' ) ); From 626b5bdee2cccfb342a594d35dca581e34355aed Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Mon, 3 Feb 2025 11:20:40 +0100 Subject: [PATCH 4/6] Require Twig ^3.18 instead of ^3.19 for PHP 8.0 compatibility --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 8e2524b..1fb40ea 100644 --- a/composer.json +++ b/composer.json @@ -36,12 +36,12 @@ ] }, "require" : { - "twig/twig":"^3.19", - "php":">=8.0", + "php":"^8.0", + "twig/twig": "^3.18", "twig/string-extra": "^3.19", "twig/intl-extra": "^3.19", "twig/html-extra": "^3.19", - "twig/markdown-extra": "^3.19" + "twig/markdown-extra": "^3.18" }, "require-dev": { "wp-coding-standards/wpcs": "^2.1", From e93b0708751bedd1852d005ce43e6fab02d5d706 Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Mon, 3 Feb 2025 11:23:46 +0100 Subject: [PATCH 5/6] Require PHP 8.0 in test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f5230d..fa7ae39 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: build: strategy: matrix: - php: ['7.4'] + php: ['8.0'] fail-fast: false name: PHP ${{ matrix.php }} runs-on: ubuntu-latest From 140cda399560f3e00032aa2c893dcf65458bfe79 Mon Sep 17 00:00:00 2001 From: Mike Hermans Date: Mon, 3 Feb 2025 13:51:49 +0100 Subject: [PATCH 6/6] Require Twig ^3 --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 1fb40ea..5b4db51 100644 --- a/composer.json +++ b/composer.json @@ -37,11 +37,11 @@ }, "require" : { "php":"^8.0", - "twig/twig": "^3.18", - "twig/string-extra": "^3.19", - "twig/intl-extra": "^3.19", - "twig/html-extra": "^3.19", - "twig/markdown-extra": "^3.18" + "twig/twig": "^3", + "twig/string-extra": "^3", + "twig/intl-extra": "^3", + "twig/html-extra": "^3", + "twig/markdown-extra": "^3" }, "require-dev": { "wp-coding-standards/wpcs": "^2.1",