Skip to content

Commit f1e1fef

Browse files
committed
Update to Symfony YAML 5.0 and Twig 3.0
1 parent 3c12ea4 commit f1e1fef

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"source": "https://github.com/picocms/pico-deprecated"
2727
},
2828
"require": {
29-
"php": ">=7.0.0",
29+
"php": ">=7.2.5",
3030
"picocms/pico": "self.version"
3131
},
3232
"autoload": {

plugins/PluginApi0Plugin.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use picocms\Pico\Pico;
2424
use picocms\PicoDeprecated\AbstractPluginApiPlugin;
2525
use PicoDeprecated;
26+
use Twig\Environment as TwigEnvironment;
2627

2728
/**
2829
* Maintains backward compatibility with plugins using API version 0, written
@@ -258,11 +259,11 @@ public function onPagesLoaded(
258259
* Please note that the `before_render` event gets `$templateName` passed
259260
* without its file extension. The file extension is re-added later.
260261
*
261-
* @param \Twig_Environment &$twig Twig instance
262-
* @param string &$templateName file name of the template
263-
* @param array &$twigVariables template variables
262+
* @param TwigEnvironment &$twig Twig instance
263+
* @param string &$templateName file name of the template
264+
* @param array &$twigVariables template variables
264265
*/
265-
public function onPageRendering(\Twig_Environment &$twig, array &$twigVariables, &$templateName)
266+
public function onPageRendering(TwigEnvironment &$twig, array &$twigVariables, &$templateName)
266267
{
267268
$templateNameInfo = pathinfo($templateName) + [ 'extension' => '' ];
268269

plugins/PluginApi1Plugin.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use picocms\PicoDeprecated\AbstractPluginApiPlugin;
2424
use PicoDeprecated;
25+
use Twig\Environment as TwigEnvironment;
2526

2627
/**
2728
* Maintains backward compatibility with plugins using API version 1, written
@@ -107,7 +108,7 @@ class PluginApi1Plugin extends AbstractPluginApiPlugin
107108
* @see Pico::$twig
108109
* @see PluginApi1Plugin::onTwigRegistered()
109110
*
110-
* @var \Twig_Environment|null
111+
* @var TwigEnvironment|null
111112
*/
112113
protected $twig;
113114

@@ -286,9 +287,9 @@ public function onMetaHeaders(array &$headers)
286287
*
287288
* @see PluginApi1Plugin::$twig
288289
*
289-
* @param \Twig_Environment &$twig Twig instance
290+
* @param TwigEnvironment &$twig Twig instance
290291
*/
291-
public function onTwigRegistered(\Twig_Environment &$twig)
292+
public function onTwigRegistered(TwigEnvironment &$twig)
292293
{
293294
$this->twig = $twig;
294295
}

plugins/ThemeApi1Plugin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
use picocms\PicoDeprecated\AbstractPlugin;
2424
use PicoDeprecated;
25+
use Twig\Error\LoaderError as TwigLoaderError;
2526

2627
/**
2728
* Maintains backward compatibility with themes using API version 1, written
@@ -98,14 +99,14 @@ public function onPageRendering(&$templateName, array &$twigVariables)
9899

99100
try {
100101
$twig->loadTemplate($templateName);
101-
} catch (\Twig_Error_Loader $e) {
102+
} catch (TwigLoaderError $e) {
102103
if ($templateNameInfo['extension'] === 'twig') {
103104
try {
104105
$twig->loadTemplate($templateNameInfo['filename'] . '.html');
105106

106107
$templateName = $templateNameInfo['filename'] . '.html';
107108
$templateNameInfo['extension'] = 'html';
108-
} catch (\Twig_Error_Loader $e) {
109+
} catch (TwigLoaderError $e) {
109110
// template doesn't exist, Twig will very likely fail later
110111
}
111112
}

plugins/ThemeApi2Plugin.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
use picocms\PicoDeprecated\AbstractPlugin;
2424
use PicoDeprecated;
25+
use Twig\Environment as TwigEnvironment;
26+
use Twig\Error\LoaderError as TwigLoaderError;
27+
use Twig\Extension\EscaperExtension as TwigEscaperExtension;
28+
use Twig\Loader\LoaderInterface as TwigLoaderInterface;
2529

2630
/**
2731
* Maintains backward compatibility with themes using API version 2, written
@@ -81,13 +85,13 @@ public function onPageRendering(&$templateName, array &$twigVariables)
8185
*
8286
* @see PluginApi2Plugin::twigEscapeStrategy()
8387
*
84-
* @param \Twig_Environment &$twig Twig instance
88+
* @param TwigEnvironment &$twig Twig instance
8589
*/
86-
public function onTwigRegistered(\Twig_Environment &$twig)
90+
public function onTwigRegistered(TwigEnvironment &$twig)
8791
{
88-
if ($twig->hasExtension('Twig_Extension_Escaper')) {
89-
/** @var \Twig_Extension_Escaper $escaperExtension */
90-
$escaperExtension = $twig->getExtension('Twig_Extension_Escaper');
92+
if ($twig->hasExtension(TwigEscaperExtension::class)) {
93+
/** @var TwigEscaperExtension $escaperExtension */
94+
$escaperExtension = $twig->getExtension(TwigEscaperExtension::class);
9195
$escaperExtension->setDefaultStrategy([ $this, 'twigEscapeStrategy' ]);
9296
}
9397
}
@@ -123,18 +127,12 @@ public function twigEscapeStrategy($templateName)
123127
return false;
124128
}
125129

126-
/** @var \Twig_SourceContextLoaderInterface $twigLoader */
130+
/** @var TwigLoaderInterface $twigLoader */
127131
$twigLoader = $this->getPico()->getTwig()->getLoader();
128-
if (!$twigLoader instanceof \Twig_SourceContextLoaderInterface) {
129-
throw new \RuntimeException(
130-
"PicoDeprecated compat plugin '" . __CLASS__ . "' requires a 'Twig_SourceContextLoaderInterface' "
131-
. "Twig loader, '" . get_class($twigLoader) . "' given"
132-
);
133-
}
134132

135133
try {
136134
$templatePath = $twigLoader->getSourceContext($templateName)->getPath();
137-
} catch (\Twig\Error\LoaderError $e) {
135+
} catch (TwigLoaderError $e) {
138136
$templatePath = '';
139137
}
140138

0 commit comments

Comments
 (0)