Move functions for InkyExtension

This commit is contained in:
Fabien Potencier
2023-12-09 18:06:59 +01:00
parent bff189f19a
commit e07e9b5be3
4 changed files with 60 additions and 5 deletions
+8 -5
View File
@@ -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;
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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);
}
@@ -0,0 +1,27 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Extra\Inky\Tests;
use PHPUnit\Framework\TestCase;
use Twig\Extra\Inky\InkyExtension;
use function Twig\Extra\Inky\twig_inky;
/**
* @group legacy
*/
class LegacyFunctionsTest extends TestCase
{
public function testInlineCss()
{
$this->assertSame(InkyExtension::inky('<p>Foo</p>'), twig_inky('<p>Foo</p>'));
}
}
+2
View File
@@ -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/"