Skip to content

Commit 347bb91

Browse files
committed
feat: Upgrade Pico to PHP 8.2/8.3
Make Pico compatible with PHP 8.2 and 8.3. - Upgrade symfony/yaml config reader - Upgrade twig template engine, - Raise supported PHP version, - Remove pico/pico-deprecated - Remove redundant index files - Use pico-composer to set up a project Required Changes for users running version 2.1: - Replace composer.json from pico/pico-composer to load Pico Core via Composer - Add all required folders to project root (config/, plugins/, themes/) - Convert config file from PHP to YAML - Errors may happen due to wrong value types (eg. multiline text is not supported) - Themes may need some tweaks: - Themes need a YAML config as well - HTML files in themes need to be renamed to TWIG files - Replace twig condition »is_front_page« with »current_page.id == "index"« - Replace twig variable »page.excerpt« with »page.meta.Summary«
1 parent 09aa825 commit 347bb91

File tree

3 files changed

+32
-39
lines changed

3 files changed

+32
-39
lines changed

composer.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@
3131
"source": "https://github.com/picocms/Pico"
3232
},
3333
"require": {
34-
"php": ">=5.3.6",
34+
"php": ">=8.2.20",
3535
"ext-mbstring": "*",
36-
"twig/twig": "^1.36",
37-
"symfony/yaml" : "^2.8",
36+
"twig/twig": "^3.14",
37+
"symfony/yaml" : "^7.1",
3838
"erusev/parsedown": "1.8.0-beta-7",
3939
"erusev/parsedown-extra": "0.8.0-beta-1"
4040
},
4141
"suggest": {
4242
"picocms/pico-theme": "Pico requires a theme to actually display the contents of your website. This is Pico's official default theme.",
43-
"picocms/pico-deprecated": "PicoDeprecated's purpose is to maintain backward compatibility to older versions of Pico.",
4443
"picocms/composer-installer": "This Composer plugin is responsible for installing Pico plugins and themes using the Composer package manager."
4544
},
4645
"autoload": {
@@ -49,11 +48,5 @@
4948
"PicoPluginInterface": "lib/",
5049
"AbstractPicoPlugin": "lib/"
5150
}
52-
},
53-
"extra": {
54-
"branch-alias": {
55-
"dev-master": "2.1.x-dev",
56-
"dev-pico-3.0": "3.0.x-dev"
57-
}
5851
}
5952
}

lib/Pico.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class Pico
307307
* Twig instance used for template parsing
308308
*
309309
* @see Pico::getTwig()
310-
* @var Twig_Environment|null
310+
* @var \TwigEnvironment|null
311311
*/
312312
protected $twig;
313313

@@ -2095,27 +2095,27 @@ public function getPageTree()
20952095
* @see https://twig.symfony.com/ Twig website
20962096
* @see https://github.com/twigphp/Twig Twig on GitHub
20972097
*
2098-
* @return Twig_Environment|null Twig template engine
2098+
* @return \TwigEnvironment|null Twig template engine
20992099
*/
21002100
public function getTwig()
21012101
{
21022102
if ($this->twig === null) {
21032103
$twigConfig = $this->getConfig('twig_config');
21042104

2105-
$twigLoader = new Twig_Loader_Filesystem($this->getThemesDir() . $this->getTheme());
2106-
$this->twig = new Twig_Environment($twigLoader, $twigConfig);
2105+
$twigLoader = new \Twig\Loader\FilesystemLoader($this->getThemesDir() . $this->getTheme());
2106+
$this->twig = new \Twig\Environment($twigLoader, $twigConfig);
21072107
$this->twig->addExtension(new PicoTwigExtension($this));
21082108

21092109
if (!empty($twigConfig['debug'])) {
2110-
$this->twig->addExtension(new Twig_Extension_Debug());
2110+
$this->twig->addExtension(new \Twig\Extension\DebugExtension());
21112111
}
21122112

21132113
// register content filter
21142114
// we pass the $pages array by reference to prevent multiple parser runs for the same page
21152115
// this is the reason why we can't register this filter as part of PicoTwigExtension
21162116
$pico = $this;
21172117
$pages = &$this->pages;
2118-
$this->twig->addFilter(new Twig_SimpleFilter(
2118+
$this->twig->addFilter(new \Twig\TwigFilter(
21192119
'content',
21202120
function ($page) use ($pico, &$pages) {
21212121
if (isset($pages[$page])) {
@@ -2156,7 +2156,7 @@ protected function getTwigVariables()
21562156
'theme_url' => $this->getConfig('themes_url') . $this->getTheme(),
21572157
'site_title' => $this->getConfig('site_title'),
21582158
'meta' => $this->meta,
2159-
'content' => new Twig_Markup($this->content, 'UTF-8'),
2159+
'content' => new \Twig\Markup($this->content, 'UTF-8'),
21602160
'pages' => $this->pages,
21612161
'previous_page' => $this->previousPage,
21622162
'current_page' => $this->currentPage,

lib/PicoTwigExtension.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @license http://opensource.org/licenses/MIT The MIT License
1919
* @version 2.1
2020
*/
21-
class PicoTwigExtension extends Twig_Extension
21+
class PicoTwigExtension extends \Twig\Extension\AbstractExtension
2222
{
2323
/**
2424
* Current instance of Pico
@@ -53,7 +53,7 @@ public function getPico()
5353
/**
5454
* Returns the name of the extension
5555
*
56-
* @see Twig_ExtensionInterface::getName()
56+
* @see \Twig\Extension\AbstractExtension::getName()
5757
*
5858
* @return string the extension name
5959
*/
@@ -65,38 +65,38 @@ public function getName()
6565
/**
6666
* Returns a list of Pico-specific Twig filters
6767
*
68-
* @see Twig_ExtensionInterface::getFilters()
68+
* @see \Twig\Extension\ExtensionInterface::getFilters()
6969
*
70-
* @return Twig_SimpleFilter[] array of Pico's Twig filters
70+
* @return \Twig\TwigFilter[] array of Pico's Twig filters
7171
*/
7272
public function getFilters()
7373
{
7474
return array(
75-
'markdown' => new Twig_SimpleFilter(
75+
'markdown' => new \Twig\TwigFilter(
7676
'markdown',
7777
array($this, 'markdownFilter'),
7878
array('is_safe' => array('html'))
7979
),
80-
'map' => new Twig_SimpleFilter('map', array($this, 'mapFilter')),
81-
'sort_by' => new Twig_SimpleFilter('sort_by', array($this, 'sortByFilter')),
82-
'link' => new Twig_SimpleFilter('link', array($this->pico, 'getPageUrl')),
83-
'url' => new Twig_SimpleFilter('url', array($this->pico, 'substituteUrl'))
80+
'map' => new \Twig\TwigFilter('map', array($this, 'mapFilter')),
81+
'sort_by' => new \Twig\TwigFilter('sort_by', array($this, 'sortByFilter')),
82+
'link' => new \Twig\TwigFilter('link', array($this->pico, 'getPageUrl')),
83+
'url' => new \Twig\TwigFilter('url', array($this->pico, 'substituteUrl'))
8484
);
8585
}
8686

8787
/**
8888
* Returns a list of Pico-specific Twig functions
8989
*
90-
* @see Twig_ExtensionInterface::getFunctions()
90+
* @see \Twig\Extension\ExtensionInterface::getFunctions()
9191
*
92-
* @return Twig_SimpleFunction[] array of Pico's Twig functions
92+
* @return \Twig\TwigFunction[] array of Pico's Twig functions
9393
*/
9494
public function getFunctions()
9595
{
9696
return array(
97-
'url_param' => new Twig_SimpleFunction('url_param', array($this, 'urlParamFunction')),
98-
'form_param' => new Twig_SimpleFunction('form_param', array($this, 'formParamFunction')),
99-
'pages' => new Twig_SimpleFunction('pages', array($this, 'pagesFunction'))
97+
'url_param' => new \Twig\TwigFunction('url_param', array($this, 'urlParamFunction')),
98+
'form_param' => new \Twig\TwigFunction('form_param', array($this, 'formParamFunction')),
99+
'pages' => new \Twig\TwigFunction('pages', array($this, 'pagesFunction'))
100100
);
101101
}
102102

@@ -136,12 +136,12 @@ public function markdownFilter($markdown, array $meta = array(), $singleLine = f
136136
*
137137
* @return array mapped values
138138
*
139-
* @throws Twig_Error_Runtime
139+
* @throws \Twig\Error\RuntimeError
140140
*/
141141
public function mapFilter($var, $mapKeyPath)
142142
{
143143
if (!is_array($var) && (!is_object($var) || !($var instanceof Traversable))) {
144-
throw new Twig_Error_Runtime(sprintf(
144+
throw new \Twig\Error\RuntimeError(sprintf(
145145
'The map filter only works with arrays or "Traversable", got "%s"',
146146
is_object($var) ? get_class($var) : gettype($var)
147147
));
@@ -178,20 +178,20 @@ public function mapFilter($var, $mapKeyPath)
178178
*
179179
* @return array sorted array
180180
*
181-
* @throws Twig_Error_Runtime
181+
* @throws \Twig\Error\RuntimeError
182182
*/
183183
public function sortByFilter($var, $sortKeyPath, $fallback = 'bottom')
184184
{
185185
if (is_object($var) && ($var instanceof Traversable)) {
186186
$var = iterator_to_array($var, true);
187187
} elseif (!is_array($var)) {
188-
throw new Twig_Error_Runtime(sprintf(
188+
throw new \Twig\Error\RuntimeError(sprintf(
189189
'The sort_by filter only works with arrays or "Traversable", got "%s"',
190190
is_object($var) ? get_class($var) : gettype($var)
191191
));
192192
}
193193
if (($fallback !== 'top') && ($fallback !== 'bottom') && ($fallback !== 'keep') && ($fallback !== "remove")) {
194-
throw new Twig_Error_Runtime(
194+
throw new \Twig\Error\RuntimeError(
195195
'The sort_by filter only supports the "top", "bottom", "keep" and "remove" fallbacks'
196196
);
197197
}
@@ -399,7 +399,7 @@ public function formParamFunction($name, $filter = '', $options = null, $flags =
399399
* returns Pico's full pages array.
400400
*
401401
* If `$depth` is negative after taking `$offset` into consideration, the
402-
* function will throw a {@see Twig_Error_Runtime} exception, since this
402+
* function will throw a {@see \Twig\Error\RuntimeError} exception, since this
403403
* would simply make no sense and is likely an error. Passing a negative
404404
* `$depthOffset` is equivalent to passing `$depthOffset = 0`.
405405
*
@@ -421,7 +421,7 @@ public function formParamFunction($name, $filter = '', $options = null, $flags =
421421
*
422422
* @return array[] the data of the matched pages
423423
*
424-
* @throws Twig_Error_Runtime
424+
* @throws \Twig\Error\RuntimeError
425425
*/
426426
public function pagesFunction($start = '', $depth = 0, $depthOffset = 0, $offset = 1)
427427
{
@@ -443,7 +443,7 @@ public function pagesFunction($start = '', $depth = 0, $depthOffset = 0, $offset
443443
$depthOffset = $depthOffset + $offset;
444444

445445
if (($depth !== null) && ($depth < 0)) {
446-
throw new Twig_Error_Runtime('The pages function doesn\'t support negative depths');
446+
throw new \Twig\Error\RuntimeError('The pages function doesn\'t support negative depths');
447447
}
448448

449449
$pageTree = $this->getPico()->getPageTree();

0 commit comments

Comments
 (0)