diff --git a/extra/cssinliner-extra/CssInlinerExtension.php b/extra/cssinliner-extra/CssInlinerExtension.php index 4d8b75a5623..679e9165716 100644 --- a/extra/cssinliner-extra/CssInlinerExtension.php +++ b/extra/cssinliner-extra/CssInlinerExtension.php @@ -20,17 +20,20 @@ class CssInlinerExtension extends AbstractExtension public function getFilters() { return [ - new TwigFilter('inline_css', 'Twig\\Extra\\CssInliner\\twig_inline_css', ['is_safe' => ['all']]), + new TwigFilter('inline_css', [self::class, 'inlineCss'], ['is_safe' => ['all']]), ]; } -} -function twig_inline_css(string $body, string ...$css): string -{ - static $inliner; - if (null === $inliner) { - $inliner = new CssToInlineStyles(); + /** + * @internal + */ + public static function inlineCss(string $body, string ...$css): string + { + static $inliner; + if (null === $inliner) { + $inliner = new CssToInlineStyles(); + } + + return $inliner->convert($body, implode("\n", $css)); } - - return $inliner->convert($body, implode("\n", $css)); } diff --git a/extra/cssinliner-extra/Resources/functions.php b/extra/cssinliner-extra/Resources/functions.php new file mode 100644 index 00000000000..c4b32db2d95 --- /dev/null +++ b/extra/cssinliner-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\CssInliner; + +/** + * @internal + * @deprecated since Twig 3.9.0 + */ +function twig_inline_css(string $body, string ...$css): string +{ + trigger_deprecation('twig/cssinliner-extra', '3.9.0', 'Using the internal "%s" function is deprecated.', __FUNCTION__); + + return CssInlinerExtension::inlineCss($body, ...$css); +} diff --git a/extra/cssinliner-extra/composer.json b/extra/cssinliner-extra/composer.json index 32be7b44de4..0a279c61323 100644 --- a/extra/cssinliner-extra/composer.json +++ b/extra/cssinliner-extra/composer.json @@ -16,6 +16,7 @@ ], "require": { "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.5|^3", "tijsverkoyen/css-to-inline-styles": "^2.0", "twig/twig": "^3.0" }, @@ -23,6 +24,7 @@ "symfony/phpunit-bridge": "^6.4|^7.0" }, "autoload": { + "files": [ "Resources/functions.php" ], "psr-4" : { "Twig\\Extra\\CssInliner\\" : "" }, "exclude-from-classmap": [ "/Tests/"