diff --git a/src/DependencyInjection/SetonoSyliusGiftCardExtension.php b/src/DependencyInjection/SetonoSyliusGiftCardExtension.php index f9d3ec8f..80fca066 100644 --- a/src/DependencyInjection/SetonoSyliusGiftCardExtension.php +++ b/src/DependencyInjection/SetonoSyliusGiftCardExtension.php @@ -23,23 +23,11 @@ public function load(array $configs, ContainerBuilder $container): void $container->setParameter('setono_sylius_gift_card.code_length', $config['code_length']); - // Load default CSS file path - if ($container->hasParameter('kernel.project_dir')) { - /** - * @psalm-suppress UndefinedDocblockClass - * - * @var string $kernelProjectDir - */ - $kernelProjectDir = $container->getParameter('kernel.project_dir'); - $fileLocator = new FileLocator([ - $kernelProjectDir . '/private', - __DIR__ . '/../Resources/private', - ]); - $container->setParameter( - 'setono_sylius_gift_card.default_css_file_path', - $fileLocator->locate('default-gift-card-configuration-css.txt') - ); - } + // Load default CSS file + $container->setParameter( + 'setono_sylius_gift_card.default_css_file', + '@SetonoSyliusGiftCardPlugin/Shop/GiftCard/defaultGiftCardConfiguration.css.twig' + ); $this->registerResources('setono_sylius_gift_card', $config['driver'], $config['resources'], $container); diff --git a/src/Provider/DefaultPdfCssProvider.php b/src/Provider/DefaultPdfCssProvider.php index 54b14b54..30c0abe5 100644 --- a/src/Provider/DefaultPdfCssProvider.php +++ b/src/Provider/DefaultPdfCssProvider.php @@ -4,24 +4,22 @@ namespace Setono\SyliusGiftCardPlugin\Provider; +use Twig\Environment; + final class DefaultPdfCssProvider implements DefaultPdfCssProviderInterface { - private string $defaultCssFilePath; + private string $defaultCssFile; + + private Environment $twig; - public function __construct(string $defaultCssFilePath) + public function __construct(string $defaultCssFile, Environment $twig) { - $this->defaultCssFilePath = $defaultCssFilePath; + $this->defaultCssFile = $defaultCssFile; + $this->twig = $twig; } public function getDefaultCss(): string { - // TODO: When dropping Symfony 4.4, switch to Symfony File class - $content = file_get_contents($this->defaultCssFilePath); - - if (false === $content) { - return ''; - } - - return $content; + return $this->twig->render($this->defaultCssFile); } } diff --git a/src/Resources/config/services/provider.xml b/src/Resources/config/services/provider.xml index 74cf74d9..1ad9b94c 100644 --- a/src/Resources/config/services/provider.xml +++ b/src/Resources/config/services/provider.xml @@ -31,7 +31,8 @@ - %setono_sylius_gift_card.default_css_file_path% + %setono_sylius_gift_card.default_css_file% + diff --git a/src/Resources/private/default-gift-card-configuration-css.txt b/src/Resources/views/Shop/GiftCard/defaultGiftCardConfiguration.css.twig similarity index 100% rename from src/Resources/private/default-gift-card-configuration-css.txt rename to src/Resources/views/Shop/GiftCard/defaultGiftCardConfiguration.css.twig diff --git a/tests/Unit/Provider/DefaultPdfCssProviderTest.php b/tests/Unit/Provider/DefaultPdfCssProviderTest.php new file mode 100644 index 00000000..c3754606 --- /dev/null +++ b/tests/Unit/Provider/DefaultPdfCssProviderTest.php @@ -0,0 +1,30 @@ +prophesize(Environment::class); + $twig->render($cssTemplateFile)->willReturn($css); + + $defaultPdfCssProvider = new DefaultPdfCssProvider($cssTemplateFile, $twig->reveal()); + + $this->assertEquals($css, $defaultPdfCssProvider->getDefaultCss()); + } +}