Skip to content

Commit

Permalink
Move functions for CssInlinerExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Dec 9, 2023
1 parent 7ff695e commit 5ab7bdf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
21 changes: 12 additions & 9 deletions extra/cssinliner-extra/CssInlinerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
23 changes: 23 additions & 0 deletions extra/cssinliner-extra/Resources/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* 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);
}
2 changes: 2 additions & 0 deletions extra/cssinliner-extra/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
],
"require": {
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.5|^3",
"tijsverkoyen/css-to-inline-styles": "^2.0",
"twig/twig": "^3.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^6.4|^7.0"
},
"autoload": {
"files": [ "Resources/functions.php" ],
"psr-4" : { "Twig\\Extra\\CssInliner\\" : "" },
"exclude-from-classmap": [
"/Tests/"
Expand Down

0 comments on commit 5ab7bdf

Please sign in to comment.