From 5cae5bea56326861a19e5ea9727bee5a09e2bf9c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 9 Dec 2023 18:06:59 +0100 Subject: [PATCH] Move functions for InkyExtension --- extra/inky-extra/InkyExtension.php | 13 ++++++++----- extra/inky-extra/Resources/functions.php | 23 +++++++++++++++++++++++ extra/inky-extra/composer.json | 2 ++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 extra/inky-extra/Resources/functions.php diff --git a/extra/inky-extra/InkyExtension.php b/extra/inky-extra/InkyExtension.php index 1ee2b515660..374cb7efbc5 100644 --- a/extra/inky-extra/InkyExtension.php +++ b/extra/inky-extra/InkyExtension.php @@ -20,12 +20,15 @@ class InkyExtension extends AbstractExtension public function getFilters() { return [ - new TwigFilter('inky_to_html', 'Twig\\Extra\\Inky\\twig_inky', ['is_safe' => ['html']]), + new TwigFilter('inky_to_html', [self::class, 'inky'], ['is_safe' => ['html']]), ]; } -} -function twig_inky(string $body): string -{ - return false === ($html = Pinky\transformString($body)->saveHTML()) ? '' : $html; + /** + * @internal + */ + public static function inky(string $body): string + { + return false === ($html = Pinky\transformString($body)->saveHTML()) ? '' : $html; + } } diff --git a/extra/inky-extra/Resources/functions.php b/extra/inky-extra/Resources/functions.php new file mode 100644 index 00000000000..feef69eabe8 --- /dev/null +++ b/extra/inky-extra/Resources/functions.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Twig\Extra\Inky; + +/** + * @internal + * @deprecated since Twig 3.9.0 + */ +function twig_inky(string $body): string +{ + trigger_deprecation('twig/inky-extra', '3.9.0', 'Using the internal "%s" function is deprecated.', __FUNCTION__); + + return InkyExtension::inky($body); +} diff --git a/extra/inky-extra/composer.json b/extra/inky-extra/composer.json index 2cb5a5ad308..9eacfc55b35 100644 --- a/extra/inky-extra/composer.json +++ b/extra/inky-extra/composer.json @@ -16,6 +16,7 @@ ], "require": { "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.5|^3", "lorenzo/pinky": "^1.0.5", "twig/twig": "^3.0" }, @@ -23,6 +24,7 @@ "symfony/phpunit-bridge": "^6.4|^7.0" }, "autoload": { + "files": [ "Resources/functions.php" ], "psr-4" : { "Twig\\Extra\\Inky\\" : "" }, "exclude-from-classmap": [ "/Tests/"