Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
]
},
"require" : {
"twig/twig":"^1.2",
"twig/extensions":"^1.3",
"php":"^7.1|^8.0"
"php":"^8.0",
"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",
Expand Down
23 changes: 15 additions & 8 deletions lib/clarkson-core-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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(
Expand All @@ -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() );
}

/**
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/clarkson-core-twig-extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down