From 09b694f26659981b339c7ced4b0683b8e79117fd Mon Sep 17 00:00:00 2001 From: endroid Date: Fri, 9 Feb 2018 21:53:50 +0000 Subject: [PATCH] Remove old extension --- composer.json | 6 --- src/Twig/Extension/QrCodeExtension.php | 46 ++----------------- src/Twig/Extension/QrCodeUriExtension.php | 36 --------------- tests/Twig/Extension/QrCodeExtensionTest.php | 41 +---------------- .../Twig/Extension/QrCodeUriExtensionTest.php | 23 ---------- 5 files changed, 5 insertions(+), 147 deletions(-) delete mode 100755 src/Twig/Extension/QrCodeUriExtension.php delete mode 100755 tests/Twig/Extension/QrCodeUriExtensionTest.php diff --git a/composer.json b/composer.json index c664d0c..a464bda 100755 --- a/composer.json +++ b/composer.json @@ -27,12 +27,6 @@ "symfony/phpunit-bridge": "^3.0|^4.0", "symfony/routing": "^3.0|^4.0" }, - "suggest": { - "twig/twig": "To enable the twig extension" - }, - "conflict": { - "twig/twig": "<1.34.2||>=2.0.0,<2.4.4" - }, "autoload": { "psr-4": { "Endroid\\QrCode\\": "src/" diff --git a/src/Twig/Extension/QrCodeExtension.php b/src/Twig/Extension/QrCodeExtension.php index 7431292..db25749 100755 --- a/src/Twig/Extension/QrCodeExtension.php +++ b/src/Twig/Extension/QrCodeExtension.php @@ -10,65 +10,27 @@ namespace Endroid\QrCode\Twig\Extension; use Endroid\QrCode\Factory\QrCodeFactoryInterface; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -use Symfony\Component\Routing\RouterInterface; use Twig_Extension; use Twig_SimpleFunction; -/** - * @deprecated as of 3.1 and will be removed in 4.0. Use the QrCodeRoutingExtension and QrCodeUriExtension instead. - */ -class QrCodeExtension extends Twig_Extension +final class QrCodeExtension extends Twig_Extension { private $qrCodeFactory; - private $router; - public function __construct(QrCodeFactoryInterface $qrCodeFactory, RouterInterface $router) + public function __construct(QrCodeFactoryInterface $qrCodeFactory) { $this->qrCodeFactory = $qrCodeFactory; - $this->router = $router; } public function getFunctions(): array { return [ - new Twig_SimpleFunction('qr_code_path', [$this, 'qrCodePathFunction']), - new Twig_SimpleFunction('qr_code_url', [$this, 'qrCodeUrlFunction']), - new Twig_SimpleFunction('qr_code_data_uri', [$this, 'qrCodeDataUriFunction']), + new Twig_SimpleFunction('qrcode_data_uri', [$this, 'qrCodeDataUriFunction']), ]; } - public function qrCodeUrlFunction(string $text, array $options = []): string - { - @trigger_error(sprintf('Using %s is deprecated as of 3.1 and will be removed in 4.0. Install the EndroidQrCodeBundle instead.', __METHOD__), E_USER_DEPRECATED); - - return $this->getQrCodeReference($text, $options, UrlGeneratorInterface::ABSOLUTE_URL); - } - - public function qrCodePathFunction(string $text, array $options = []): string - { - @trigger_error(sprintf('Using %s is deprecated as of 3.1 and will be removed in 4.0. Install the EndroidQrCodeBundle instead.', __METHOD__), E_USER_DEPRECATED); - - return $this->getQrCodeReference($text, $options, UrlGeneratorInterface::ABSOLUTE_PATH); - } - - public function getQrCodeReference(string $text, array $options = [], int $referenceType): string - { - $qrCode = $this->qrCodeFactory->create($text, $options); - $supportedExtensions = $qrCode->getWriter()->getSupportedExtensions(); - - $options['text'] = $text; - $options['extension'] = current($supportedExtensions); - - return $this->router->generate('qr_code_generate', $options, $referenceType); - } - public function qrCodeDataUriFunction(string $text, array $options = []): string { - @trigger_error(sprintf('Using %s is deprecated as of 3.1 and will be removed in 4.0. Use %s::qrCodeDataUriFunction() instead.', __METHOD__, QrCodeUriExtension::class), E_USER_DEPRECATED); - - $qrCode = $this->qrCodeFactory->create($text, $options); - - return $qrCode->writeDataUri(); + return $this->qrCodeFactory->create($text, $options)->writeDataUri(); } } diff --git a/src/Twig/Extension/QrCodeUriExtension.php b/src/Twig/Extension/QrCodeUriExtension.php deleted file mode 100755 index 9de44e5..0000000 --- a/src/Twig/Extension/QrCodeUriExtension.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Endroid\QrCode\Twig\Extension; - -use Endroid\QrCode\Factory\QrCodeFactoryInterface; -use Twig_Extension; -use Twig_SimpleFunction; - -final class QrCodeUriExtension extends Twig_Extension -{ - private $qrCodeFactory; - - public function __construct(QrCodeFactoryInterface $qrCodeFactory) - { - $this->qrCodeFactory = $qrCodeFactory; - } - - public function getFunctions(): array - { - return [ - new Twig_SimpleFunction('qrcode_data_uri', [$this, 'qrCodeDataUriFunction']), - ]; - } - - public function qrCodeDataUriFunction(string $text, array $options = []): string - { - return $this->qrCodeFactory->create($text, $options)->writeDataUri(); - } -} diff --git a/tests/Twig/Extension/QrCodeExtensionTest.php b/tests/Twig/Extension/QrCodeExtensionTest.php index e0ccf03..0eaa6b5 100755 --- a/tests/Twig/Extension/QrCodeExtensionTest.php +++ b/tests/Twig/Extension/QrCodeExtensionTest.php @@ -12,51 +12,12 @@ use Endroid\QrCode\Factory\QrCodeFactory; use Endroid\QrCode\Twig\Extension\QrCodeExtension; use PHPUnit\Framework\TestCase; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -use Symfony\Component\Routing\RouterInterface; class QrCodeExtensionTest extends TestCase { - /** - * @group legacy - * @expectedDeprecation Using Endroid\QrCode\Twig\Extension\QrCodeExtension::qrCodeDataUriFunction is deprecated as of 3.1 and will be removed in 4.0. Use Endroid\QrCode\Twig\Extension\QrCodeUriExtension::qrCodeDataUriFunction() instead. - */ public function testQrCodeDataUriFunction() { - $router = $this->prophesize(RouterInterface::class); - $extension = new QrCodeExtension(new QrCodeFactory(), $router->reveal()); + $extension = new QrCodeExtension(new QrCodeFactory()); $this->assertStringStartsWith('data:image/png;base64,', $extension->qrCodeDataUriFunction('Foobar')); } - - /** - * @group legacy - * @expectedDeprecation Using Endroid\QrCode\Twig\Extension\QrCodeExtension::qrCodePathFunction is deprecated as of 3.1 and will be removed in 4.0. Install the EndroidQrCodeBundle instead. - */ - public function testQrCodePathFunction() - { - $router = $this->prophesize(RouterInterface::class); - $extension = new QrCodeExtension(new QrCodeFactory(), $router->reveal()); - - $router - ->generate('qr_code_generate', ['extension' => 'png', 'text' => 'Foobar'], UrlGeneratorInterface::ABSOLUTE_PATH) - ->willReturn('/some-qr-code-path'); - - $this->assertSame('/some-qr-code-path', $extension->qrCodePathFunction('Foobar')); - } - - /** - * @group legacy - * @expectedDeprecation Using Endroid\QrCode\Twig\Extension\QrCodeExtension::qrCodeUrlFunction is deprecated as of 3.1 and will be removed in 4.0. Install the EndroidQrCodeBundle instead. - */ - public function testQrCodeUrlFunction() - { - $router = $this->prophesize(RouterInterface::class); - $extension = new QrCodeExtension(new QrCodeFactory(), $router->reveal()); - - $router - ->generate('qr_code_generate', ['extension' => 'png', 'text' => 'Foobar'], UrlGeneratorInterface::ABSOLUTE_URL) - ->willReturn('https://some-qr-code-url'); - - $this->assertSame('https://some-qr-code-url', $extension->qrCodeUrlFunction('Foobar')); - } } diff --git a/tests/Twig/Extension/QrCodeUriExtensionTest.php b/tests/Twig/Extension/QrCodeUriExtensionTest.php deleted file mode 100755 index 883fb95..0000000 --- a/tests/Twig/Extension/QrCodeUriExtensionTest.php +++ /dev/null @@ -1,23 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Endroid\QrCode\Tests\Twig\Extension; - -use Endroid\QrCode\Factory\QrCodeFactory; -use Endroid\QrCode\Twig\Extension\QrCodeUriExtension; -use PHPUnit\Framework\TestCase; - -class QrCodeUriExtensionTest extends TestCase -{ - public function testQrCodeDataUriFunction() - { - $extension = new QrCodeUriExtension(new QrCodeFactory()); - $this->assertStringStartsWith('data:image/png;base64,', $extension->qrCodeDataUriFunction('Foobar')); - } -}