From f9181fc6f9174932daa9b51cd3b1f500cbe58b98 Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 15 Feb 2022 21:21:19 +0000 Subject: [PATCH] Surprisingly painless upgrade to Twig 3.x. --- composer.json | 8 +- composer.lock | 299 +++++++++++++++++++-------------------------- src/Template.php | 10 +- src/TwigMisuzu.php | 77 ++++++++---- 4 files changed, 188 insertions(+), 206 deletions(-) diff --git a/composer.json b/composer.json index fc21a44b..e4214492 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,9 @@ { "require": { - "twig/twig": "^2.0", + "twig/twig": "^3.0", "swiftmailer/swiftmailer": "~6.0", "erusev/parsedown": "~1.6", "geoip2/geoip2": "~2.0", - "twig/extensions": "^1.5", "jublonet/codebird-php": "^3.1", "chillerlan/php-qrcode": "^3.0", "whichbrowser/parser": "^2.0" @@ -21,6 +20,9 @@ ] }, "config": { - "preferred-install": "dist" + "preferred-install": "dist", + "allow-plugins": { + "composer/installers": true + } } } diff --git a/composer.lock b/composer.lock index efc0dc38..fbe74b9e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,28 +4,29 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ce45fc99f5187b5f6e6e63b3bbd89ce9", + "content-hash": "74b2bbca53906a66f78c659eb5d47a89", "packages": [ { "name": "chillerlan/php-qrcode", - "version": "3.4.0", + "version": "3.4.1", "source": { "type": "git", "url": "https://github.com/chillerlan/php-qrcode.git", - "reference": "d8bf297e6843a53aeaa8f3285ce04fc349d133d6" + "reference": "468603b687a5fe75c1ff33857a45f1726c7b95a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/d8bf297e6843a53aeaa8f3285ce04fc349d133d6", - "reference": "d8bf297e6843a53aeaa8f3285ce04fc349d133d6", + "url": "https://api.github.com/repos/chillerlan/php-qrcode/zipball/468603b687a5fe75c1ff33857a45f1726c7b95a9", + "reference": "468603b687a5fe75c1ff33857a45f1726c7b95a9", "shasum": "" }, "require": { - "chillerlan/php-settings-container": "^1.2", + "chillerlan/php-settings-container": "^1.2.2", "ext-mbstring": "*", - "php": "^7.2" + "php": "^7.2 || ^8.0" }, "require-dev": { + "phan/phan": "^3.2.2", "phpunit/phpunit": "^8.5", "setasign/fpdf": "^1.8.2" }, @@ -69,7 +70,7 @@ ], "support": { "issues": "https://github.com/chillerlan/php-qrcode/issues", - "source": "https://github.com/chillerlan/php-qrcode/tree/3.4.0" + "source": "https://github.com/chillerlan/php-qrcode/tree/3.4.1" }, "funding": [ { @@ -81,28 +82,28 @@ "type": "ko_fi" } ], - "time": "2020-11-18T20:51:41+00:00" + "time": "2021-09-03T17:54:45+00:00" }, { "name": "chillerlan/php-settings-container", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/chillerlan/php-settings-container.git", - "reference": "b9b0431dffd74102ee92348a63b4c33fc8ba639b" + "reference": "d1b5284d6eb3a767459738bb0b20073f0cb3eeaf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/b9b0431dffd74102ee92348a63b4c33fc8ba639b", - "reference": "b9b0431dffd74102ee92348a63b4c33fc8ba639b", + "url": "https://api.github.com/repos/chillerlan/php-settings-container/zipball/d1b5284d6eb3a767459738bb0b20073f0cb3eeaf", + "reference": "d1b5284d6eb3a767459738bb0b20073f0cb3eeaf", "shasum": "" }, "require": { "ext-json": "*", - "php": "^7.2" + "php": "^7.2 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^8.3" + "phpunit/phpunit": "^8.4" }, "type": "library", "autoload": { @@ -133,20 +134,30 @@ "issues": "https://github.com/chillerlan/php-settings-container/issues", "source": "https://github.com/chillerlan/php-settings-container" }, - "time": "2019-09-10T00:09:44+00:00" + "funding": [ + { + "url": "https://www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4", + "type": "custom" + }, + { + "url": "https://ko-fi.com/codemasher", + "type": "ko_fi" + } + ], + "time": "2021-09-03T17:33:25+00:00" }, { "name": "composer/ca-bundle", - "version": "1.2.10", + "version": "1.3.1", "source": { "type": "git", "url": "https://github.com/composer/ca-bundle.git", - "reference": "9fdb22c2e97a614657716178093cd1da90a64aa8" + "reference": "4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/ca-bundle/zipball/9fdb22c2e97a614657716178093cd1da90a64aa8", - "reference": "9fdb22c2e97a614657716178093cd1da90a64aa8", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b", + "reference": "4c679186f2aca4ab6a0f1b0b9cf9252decb44d0b", "shasum": "" }, "require": { @@ -158,7 +169,7 @@ "phpstan/phpstan": "^0.12.55", "psr/log": "^1.0", "symfony/phpunit-bridge": "^4.2 || ^5", - "symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0" + "symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0" }, "type": "library", "extra": { @@ -193,7 +204,7 @@ "support": { "irc": "irc://irc.freenode.org/composer", "issues": "https://github.com/composer/ca-bundle/issues", - "source": "https://github.com/composer/ca-bundle/tree/1.2.10" + "source": "https://github.com/composer/ca-bundle/tree/1.3.1" }, "funding": [ { @@ -209,20 +220,20 @@ "type": "tidelift" } ], - "time": "2021-06-07T13:58:28+00:00" + "time": "2021-10-28T20:44:15+00:00" }, { "name": "composer/installers", - "version": "v1.11.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/composer/installers.git", - "reference": "ae03311f45dfe194412081526be2e003960df74b" + "reference": "d20a64ed3c94748397ff5973488761b22f6d3f19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/installers/zipball/ae03311f45dfe194412081526be2e003960df74b", - "reference": "ae03311f45dfe194412081526be2e003960df74b", + "url": "https://api.github.com/repos/composer/installers/zipball/d20a64ed3c94748397ff5973488761b22f6d3f19", + "reference": "d20a64ed3c94748397ff5973488761b22f6d3f19", "shasum": "" }, "require": { @@ -321,6 +332,7 @@ "modx", "moodle", "osclass", + "pantheon", "phpbb", "piwik", "ppi", @@ -343,7 +355,7 @@ ], "support": { "issues": "https://github.com/composer/installers/issues", - "source": "https://github.com/composer/installers/tree/v1.11.0" + "source": "https://github.com/composer/installers/tree/v1.12.0" }, "funding": [ { @@ -359,36 +371,32 @@ "type": "tidelift" } ], - "time": "2021-04-28T06:42:17+00:00" + "time": "2021-09-13T08:19:44+00:00" }, { "name": "doctrine/lexer", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/doctrine/lexer.git", - "reference": "e864bbf5904cb8f5bb334f99209b48018522f042" + "reference": "9c50f840f257bbb941e6f4a0e94ccf5db5c3f76c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/e864bbf5904cb8f5bb334f99209b48018522f042", - "reference": "e864bbf5904cb8f5bb334f99209b48018522f042", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/9c50f840f257bbb941e6f4a0e94ccf5db5c3f76c", + "reference": "9c50f840f257bbb941e6f4a0e94ccf5db5c3f76c", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^6.0", - "phpstan/phpstan": "^0.11.8", - "phpunit/phpunit": "^8.2" + "doctrine/coding-standard": "^9.0", + "phpstan/phpstan": "1.3", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.11" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, "autoload": { "psr-4": { "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" @@ -423,7 +431,7 @@ ], "support": { "issues": "https://github.com/doctrine/lexer/issues", - "source": "https://github.com/doctrine/lexer/tree/1.2.1" + "source": "https://github.com/doctrine/lexer/tree/1.2.2" }, "funding": [ { @@ -439,20 +447,20 @@ "type": "tidelift" } ], - "time": "2020-05-25T17:44:05+00:00" + "time": "2022-01-12T08:27:12+00:00" }, { "name": "egulias/email-validator", - "version": "3.1.1", + "version": "3.1.2", "source": { "type": "git", "url": "https://github.com/egulias/EmailValidator.git", - "reference": "c81f18a3efb941d8c4d2e025f6183b5c6d697307" + "reference": "ee0db30118f661fb166bcffbf5d82032df484697" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/c81f18a3efb941d8c4d2e025f6183b5c6d697307", - "reference": "c81f18a3efb941d8c4d2e025f6183b5c6d697307", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/ee0db30118f661fb166bcffbf5d82032df484697", + "reference": "ee0db30118f661fb166bcffbf5d82032df484697", "shasum": "" }, "require": { @@ -499,7 +507,7 @@ ], "support": { "issues": "https://github.com/egulias/EmailValidator/issues", - "source": "https://github.com/egulias/EmailValidator/tree/3.1.1" + "source": "https://github.com/egulias/EmailValidator/tree/3.1.2" }, "funding": [ { @@ -507,7 +515,7 @@ "type": "github" } ], - "time": "2021-04-01T18:37:14+00:00" + "time": "2021-10-11T09:18:27+00:00" }, { "name": "erusev/parsedown", @@ -561,16 +569,16 @@ }, { "name": "geoip2/geoip2", - "version": "v2.11.0", + "version": "v2.12.2", "source": { "type": "git", "url": "https://github.com/maxmind/GeoIP2-php.git", - "reference": "d01be5894a5c1a3381c58c9b1795cd07f96c30f7" + "reference": "83adb44ac4b9553d36b579a14673ed124583082f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/d01be5894a5c1a3381c58c9b1795cd07f96c30f7", - "reference": "d01be5894a5c1a3381c58c9b1795cd07f96c30f7", + "url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/83adb44ac4b9553d36b579a14673ed124583082f", + "reference": "83adb44ac4b9553d36b579a14673ed124583082f", "shasum": "" }, "require": { @@ -580,7 +588,8 @@ "php": ">=7.2" }, "require-dev": { - "friendsofphp/php-cs-fixer": "2.*", + "friendsofphp/php-cs-fixer": "3.*", + "phpstan/phpstan": "*", "phpunit/phpunit": "^8.0 || ^9.0", "squizlabs/php_codesniffer": "3.*" }, @@ -612,21 +621,21 @@ ], "support": { "issues": "https://github.com/maxmind/GeoIP2-php/issues", - "source": "https://github.com/maxmind/GeoIP2-php/tree/v2.11.0" + "source": "https://github.com/maxmind/GeoIP2-php/tree/v2.12.2" }, - "time": "2020-10-01T18:48:34+00:00" + "time": "2021-11-30T18:15:25+00:00" }, { "name": "jublonet/codebird-php", "version": "3.1.0", "source": { "type": "git", - "url": "https://github.com/jublonet/codebird-php.git", + "url": "https://github.com/jublo/codebird-php.git", "reference": "100a8e8f1928a5738b4476f0caf83f2c2ba6da5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jublonet/codebird-php/zipball/100a8e8f1928a5738b4476f0caf83f2c2ba6da5b", + "url": "https://api.github.com/repos/jublo/codebird-php/zipball/100a8e8f1928a5738b4476f0caf83f2c2ba6da5b", "reference": "100a8e8f1928a5738b4476f0caf83f2c2ba6da5b", "shasum": "" }, @@ -682,16 +691,16 @@ }, { "name": "maxmind-db/reader", - "version": "v1.10.1", + "version": "v1.11.0", "source": { "type": "git", "url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git", - "reference": "569bd44d97d30a4ec12c7793a33004a76d4caf18" + "reference": "b1f3c0699525336d09cc5161a2861268d9f2ae5b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/569bd44d97d30a4ec12c7793a33004a76d4caf18", - "reference": "569bd44d97d30a4ec12c7793a33004a76d4caf18", + "url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/b1f3c0699525336d09cc5161a2861268d9f2ae5b", + "reference": "b1f3c0699525336d09cc5161a2861268d9f2ae5b", "shasum": "" }, "require": { @@ -701,7 +710,7 @@ "ext-maxminddb": "<1.10.1,>=2.0.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "*", + "friendsofphp/php-cs-fixer": "3.*", "php-coveralls/php-coveralls": "^2.1", "phpstan/phpstan": "*", "phpunit/phpcov": ">=6.0.0", @@ -741,9 +750,9 @@ ], "support": { "issues": "https://github.com/maxmind/MaxMind-DB-Reader-php/issues", - "source": "https://github.com/maxmind/MaxMind-DB-Reader-php/tree/v1.10.1" + "source": "https://github.com/maxmind/MaxMind-DB-Reader-php/tree/v1.11.0" }, - "time": "2021-04-14T17:49:35+00:00" + "time": "2021-10-18T15:23:10+00:00" }, { "name": "maxmind/web-service-common", @@ -846,16 +855,16 @@ }, { "name": "swiftmailer/swiftmailer", - "version": "v6.2.7", + "version": "v6.3.0", "source": { "type": "git", "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "15f7faf8508e04471f666633addacf54c0ab5933" + "reference": "8a5d5072dca8f48460fce2f4131fcc495eec654c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/15f7faf8508e04471f666633addacf54c0ab5933", - "reference": "15f7faf8508e04471f666633addacf54c0ab5933", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/8a5d5072dca8f48460fce2f4131fcc495eec654c", + "reference": "8a5d5072dca8f48460fce2f4131fcc495eec654c", "shasum": "" }, "require": { @@ -867,7 +876,7 @@ }, "require-dev": { "mockery/mockery": "^1.0", - "symfony/phpunit-bridge": "^4.4|^5.0" + "symfony/phpunit-bridge": "^4.4|^5.4" }, "suggest": { "ext-intl": "Needed to support internationalized email addresses" @@ -905,7 +914,7 @@ ], "support": { "issues": "https://github.com/swiftmailer/swiftmailer/issues", - "source": "https://github.com/swiftmailer/swiftmailer/tree/v6.2.7" + "source": "https://github.com/swiftmailer/swiftmailer/tree/v6.3.0" }, "funding": [ { @@ -917,7 +926,8 @@ "type": "tidelift" } ], - "time": "2021-03-09T12:30:35+00:00" + "abandoned": "symfony/mailer", + "time": "2021-10-18T15:26:12+00:00" }, { "name": "symfony/polyfill-ctype", @@ -1003,21 +1013,24 @@ }, { "name": "symfony/polyfill-iconv", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-iconv.git", - "reference": "63b5bb7db83e5673936d6e3b8b3e022ff6474933" + "reference": "f1aed619e28cb077fc83fac8c4c0383578356e40" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/63b5bb7db83e5673936d6e3b8b3e022ff6474933", - "reference": "63b5bb7db83e5673936d6e3b8b3e022ff6474933", + "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/f1aed619e28cb077fc83fac8c4c0383578356e40", + "reference": "f1aed619e28cb077fc83fac8c4c0383578356e40", "shasum": "" }, "require": { "php": ">=7.1" }, + "provide": { + "ext-iconv": "*" + }, "suggest": { "ext-iconv": "For best performance" }, @@ -1032,12 +1045,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Iconv\\": "" - }, "files": [ "bootstrap.php" - ] + ], + "psr-4": { + "Symfony\\Polyfill\\Iconv\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1063,7 +1076,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-iconv/tree/v1.23.0" + "source": "https://github.com/symfony/polyfill-iconv/tree/v1.24.0" }, "funding": [ { @@ -1079,20 +1092,20 @@ "type": "tidelift" } ], - "time": "2021-05-27T09:27:20+00:00" + "time": "2022-01-04T09:04:05+00:00" }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "65bd267525e82759e7d8c4e8ceea44f398838e65" + "reference": "749045c69efb97c70d25d7463abba812e91f3a44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/65bd267525e82759e7d8c4e8ceea44f398838e65", - "reference": "65bd267525e82759e7d8c4e8ceea44f398838e65", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/749045c69efb97c70d25d7463abba812e91f3a44", + "reference": "749045c69efb97c70d25d7463abba812e91f3a44", "shasum": "" }, "require": { @@ -1114,12 +1127,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Intl\\Idn\\": "" - }, "files": [ "bootstrap.php" - ] + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Idn\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1150,7 +1163,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.23.0" + "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.24.0" }, "funding": [ { @@ -1166,11 +1179,11 @@ "type": "tidelift" } ], - "time": "2021-05-27T09:27:20+00:00" + "time": "2021-09-14T14:02:44+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", @@ -1199,12 +1212,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Intl\\Normalizer\\": "" - }, "files": [ "bootstrap.php" ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, "classmap": [ "Resources/stubs" ] @@ -1234,7 +1247,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.23.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.24.0" }, "funding": [ { @@ -1286,12 +1299,12 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, "files": [ "bootstrap.php" - ] + ], + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1411,85 +1424,24 @@ ], "time": "2021-05-27T09:17:38+00:00" }, - { - "name": "twig/extensions", - "version": "v1.5.4", - "source": { - "type": "git", - "url": "https://github.com/twigphp/Twig-extensions.git", - "reference": "57873c8b0c1be51caa47df2cdb824490beb16202" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig-extensions/zipball/57873c8b0c1be51caa47df2cdb824490beb16202", - "reference": "57873c8b0c1be51caa47df2cdb824490beb16202", - "shasum": "" - }, - "require": { - "twig/twig": "^1.27|^2.0" - }, - "require-dev": { - "symfony/phpunit-bridge": "^3.4", - "symfony/translation": "^2.7|^3.4" - }, - "suggest": { - "symfony/translation": "Allow the time_diff output to be translated" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.5-dev" - } - }, - "autoload": { - "psr-0": { - "Twig_Extensions_": "lib/" - }, - "psr-4": { - "Twig\\Extensions\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Common additional features for Twig that do not directly belong in core", - "keywords": [ - "i18n", - "text" - ], - "support": { - "issues": "https://github.com/twigphp/Twig-extensions/issues", - "source": "https://github.com/twigphp/Twig-extensions/tree/master" - }, - "abandoned": true, - "time": "2018-12-05T18:34:18+00:00" - }, { "name": "twig/twig", - "version": "v2.14.11", + "version": "v3.3.8", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "66baa66f29ee30e487e05f1679903e36eb01d727" + "reference": "972d8604a92b7054828b539f2febb0211dd5945c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/66baa66f29ee30e487e05f1679903e36eb01d727", - "reference": "66baa66f29ee30e487e05f1679903e36eb01d727", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/972d8604a92b7054828b539f2febb0211dd5945c", + "reference": "972d8604a92b7054828b539f2febb0211dd5945c", "shasum": "" }, "require": { - "php": ">=7.1.3", + "php": ">=7.2.5", "symfony/polyfill-ctype": "^1.8", - "symfony/polyfill-mbstring": "^1.3", - "symfony/polyfill-php72": "^1.8" + "symfony/polyfill-mbstring": "^1.3" }, "require-dev": { "psr/container": "^1.0", @@ -1498,13 +1450,10 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.14-dev" + "dev-master": "3.3-dev" } }, "autoload": { - "psr-0": { - "Twig_": "lib/" - }, "psr-4": { "Twig\\": "src/" } @@ -1537,7 +1486,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v2.14.11" + "source": "https://github.com/twigphp/Twig/tree/v3.3.8" }, "funding": [ { @@ -1549,7 +1498,7 @@ "type": "tidelift" } ], - "time": "2022-02-04T06:57:25+00:00" + "time": "2022-02-04T06:59:48+00:00" }, { "name": "whichbrowser/parser", diff --git a/src/Template.php b/src/Template.php index 7c0fd769..b4ac4a43 100644 --- a/src/Template.php +++ b/src/Template.php @@ -2,9 +2,9 @@ namespace Misuzu; use InvalidArgumentException; -use Twig\Environment as Twig_Environment; +use Twig\Environment as TwigEnvironment; use Twig_Extensions_Extension_Date; -use Twig\Loader\FilesystemLoader as Twig_Loader_Filesystem; +use Twig\Loader\FilesystemLoader as TwigLoaderFilesystem; final class Template { private const FILE_EXT = '.twig'; @@ -14,14 +14,14 @@ final class Template { private static $vars = []; public static function init(?string $cache = null, bool $debug = false): void { - self::$loader = new Twig_Loader_Filesystem; - self::$env = new Twig_Environment(self::$loader, [ + self::$loader = new TwigLoaderFilesystem; + self::$env = new TwigEnvironment(self::$loader, [ 'cache' => $cache ?? false, 'strict_variables' => true, 'auto_reload' => $debug, 'debug' => $debug, ]); - self::$env->addExtension(new Twig_Extensions_Extension_Date); + //self::$env->addExtension(new Twig_Extensions_Extension_Date); self::$env->addExtension(new TwigMisuzu); } diff --git a/src/TwigMisuzu.php b/src/TwigMisuzu.php index 6dc30fde..c11b5b38 100644 --- a/src/TwigMisuzu.php +++ b/src/TwigMisuzu.php @@ -1,38 +1,69 @@ Parser::instance($parser)->parseText($text)), - new Twig_Filter('perms_check', 'perms_check'), - new Twig_Filter('clamp', 'clamp'), + new TwigFilter('html_colour', 'html_colour'), + new TwigFilter('country_name', 'get_country_name'), + new TwigFilter('byte_symbol', 'byte_symbol'), + new TwigFilter('parse_text', fn(string $text, int $parser): string => Parser::instance($parser)->parseText($text)), + new TwigFilter('perms_check', 'perms_check'), + new TwigFilter('clamp', 'clamp'), + new TwigFilter('time_diff', [$this, 'timeDiff'], ['needs_environment' => true]), ]; } public function getFunctions() { return [ - new Twig_Function('url_construct', 'url_construct'), - new Twig_Function('url', 'url'), - new Twig_Function('url_list', 'url_list'), - new Twig_Function('html_avatar', 'html_avatar'), - new Twig_Function('forum_may_have_children', 'forum_may_have_children'), - new Twig_Function('forum_may_have_topics', 'forum_may_have_topics'), - new Twig_Function('forum_has_priority_voting', 'forum_has_priority_voting'), - new Twig_Function('csrf_token', fn() => CSRF::token()), - new Twig_Function('git_commit_hash', fn(bool $long = false) => GitInfo::hash($long)), - new Twig_Function('git_tag', fn() => GitInfo::tag()), - new Twig_Function('git_branch', fn() => GitInfo::branch()), - new Twig_Function('startup_time', fn(float $time = MSZ_STARTUP) => microtime(true) - $time), - new Twig_Function('sql_query_count', fn() => DB::queries()), + new TwigFunction('url_construct', 'url_construct'), + new TwigFunction('url', 'url'), + new TwigFunction('url_list', 'url_list'), + new TwigFunction('html_avatar', 'html_avatar'), + new TwigFunction('forum_may_have_children', 'forum_may_have_children'), + new TwigFunction('forum_may_have_topics', 'forum_may_have_topics'), + new TwigFunction('forum_has_priority_voting', 'forum_has_priority_voting'), + new TwigFunction('csrf_token', fn() => CSRF::token()), + new TwigFunction('git_commit_hash', fn(bool $long = false) => GitInfo::hash($long)), + new TwigFunction('git_tag', fn() => GitInfo::tag()), + new TwigFunction('git_branch', fn() => GitInfo::branch()), + new TwigFunction('startup_time', fn(float $time = MSZ_STARTUP) => microtime(true) - $time), + new TwigFunction('sql_query_count', fn() => DB::queries()), ]; } + + public static $units = [ + 'y' => 'year', + 'm' => 'month', + 'd' => 'day', + 'h' => 'hour', + 'i' => 'minute', + 's' => 'second', + ]; + + // yoinked from https://github.com/twigphp/Twig-extensions/blob/0c7a08e6de42a3c8f6a68af9628f4c8e4e00de93/src/DateExtension.php + public function timeDiff(TwigEnvironment $env, $date, $now = null) { + $date = \twig_date_converter($env, $date); + $now = \twig_date_converter($env, $now); + + $diff = $date->diff($now); + + foreach(self::$units as $attr => $unit) { + $count = $diff->{$attr}; + + if($count !== 0) { + if($count !== 1) + $unit .= 's'; + return $diff->invert ? "in {$count} {$unit}" : "{$count} {$unit} ago"; + } + } + + return 'infinite undefineds'; + } }