-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,108 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Controller/Action/Admin/GenerateEncodedExamplePdfAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusGiftCardPlugin\Controller\Action\Admin; | ||
|
||
use Setono\SyliusGiftCardPlugin\Factory\GiftCardFactoryInterface; | ||
use Setono\SyliusGiftCardPlugin\Form\Type\GiftCardConfigurationType; | ||
use Setono\SyliusGiftCardPlugin\Generator\GiftCardPdfGeneratorInterface; | ||
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
use Symfony\Component\Form\FormFactoryInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class GenerateEncodedExamplePdfAction | ||
{ | ||
private GiftCardFactoryInterface $giftCardFactory; | ||
|
||
private RepositoryInterface $giftCardConfigurationRepository; | ||
|
||
private GiftCardPdfGeneratorInterface $giftCardPdfGenerator; | ||
|
||
private FormFactoryInterface $formFactory; | ||
|
||
public function __construct( | ||
GiftCardFactoryInterface $giftCardFactory, | ||
RepositoryInterface $giftCardConfigurationRepository, | ||
GiftCardPdfGeneratorInterface $giftCardPdfGenerator, | ||
FormFactoryInterface $formFactory | ||
) { | ||
$this->giftCardFactory = $giftCardFactory; | ||
$this->giftCardConfigurationRepository = $giftCardConfigurationRepository; | ||
$this->giftCardPdfGenerator = $giftCardPdfGenerator; | ||
$this->formFactory = $formFactory; | ||
} | ||
|
||
public function __invoke(Request $request, int $id): Response | ||
{ | ||
$giftCard = $this->giftCardFactory->createExample(); | ||
/** @var GiftCardConfigurationInterface|null $giftCardConfiguration */ | ||
$giftCardConfiguration = $this->giftCardConfigurationRepository->find($id); | ||
Assert::isInstanceOf($giftCardConfiguration, GiftCardConfigurationInterface::class); | ||
|
||
$form = $this->formFactory->create(GiftCardConfigurationType::class, $giftCardConfiguration); | ||
$form->handleRequest($request); | ||
|
||
$pdfContent = $this->giftCardPdfGenerator->generateAndGetContent($giftCard, $giftCardConfiguration); | ||
|
||
return new Response(\base64_encode($pdfContent)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusGiftCardPlugin\Controller\Action\Admin; | ||
|
||
use Setono\SyliusGiftCardPlugin\Factory\GiftCardFactoryInterface; | ||
use Setono\SyliusGiftCardPlugin\Generator\GiftCardPdfGeneratorInterface; | ||
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; | ||
use Setono\SyliusGiftCardPlugin\Provider\DefaultPdfCssProviderInterface; | ||
use Sylius\Component\Resource\Repository\RepositoryInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class LoadDefaultPdfCssAction | ||
{ | ||
private GiftCardFactoryInterface $giftCardFactory; | ||
|
||
private RepositoryInterface $giftCardConfigurationRepository; | ||
|
||
private GiftCardPdfGeneratorInterface $giftCardPdfGenerator; | ||
|
||
private DefaultPdfCssProviderInterface $defaultPdfCssProvider; | ||
|
||
public function __construct( | ||
GiftCardFactoryInterface $giftCardFactory, | ||
RepositoryInterface $giftCardConfigurationRepository, | ||
GiftCardPdfGeneratorInterface $giftCardPdfGenerator, | ||
DefaultPdfCssProviderInterface $defaultPdfCssProvider | ||
) { | ||
$this->giftCardFactory = $giftCardFactory; | ||
$this->giftCardConfigurationRepository = $giftCardConfigurationRepository; | ||
$this->giftCardPdfGenerator = $giftCardPdfGenerator; | ||
$this->defaultPdfCssProvider = $defaultPdfCssProvider; | ||
} | ||
|
||
public function __invoke(int $id): JsonResponse | ||
{ | ||
$giftCard = $this->giftCardFactory->createExample(); | ||
/** @var GiftCardConfigurationInterface|null $giftCardConfiguration */ | ||
$giftCardConfiguration = $this->giftCardConfigurationRepository->find($id); | ||
Assert::isInstanceOf($giftCardConfiguration, GiftCardConfigurationInterface::class); | ||
|
||
$defaultCss = $this->defaultPdfCssProvider->getDefaultCss(); | ||
$giftCardConfiguration->setPdfRenderingCss($defaultCss); | ||
|
||
$pdfContent = $this->giftCardPdfGenerator->generateAndGetContent($giftCard, $giftCardConfiguration); | ||
|
||
return new JsonResponse([ | ||
'css' => $defaultCss, | ||
'pdfContent' => \base64_encode($pdfContent), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusGiftCardPlugin\Generator; | ||
|
||
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; | ||
use function sprintf; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class GiftCardPdfPathGenerator implements GiftCardPdfPathGeneratorInterface | ||
{ | ||
public function generatePath(GiftCardConfigurationInterface $giftCardChannelConfiguration): string | ||
{ | ||
$giftCardChannelConfigurationId = $giftCardChannelConfiguration->getId(); | ||
Assert::integer($giftCardChannelConfigurationId); | ||
|
||
return sprintf( | ||
'gift_card_configuration_pdf_%d.pdf', | ||
$giftCardChannelConfigurationId | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusGiftCardPlugin\Generator; | ||
|
||
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; | ||
|
||
interface GiftCardPdfPathGeneratorInterface | ||
{ | ||
public function generatePath(GiftCardConfigurationInterface $giftCardChannelConfiguration): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusGiftCardPlugin\Provider; | ||
|
||
use Twig\Environment; | ||
|
||
final class DefaultPdfCssProvider implements DefaultPdfCssProviderInterface | ||
{ | ||
private string $defaultCssFile; | ||
|
||
private Environment $twig; | ||
|
||
public function __construct(string $defaultCssFile, Environment $twig) | ||
{ | ||
$this->defaultCssFile = $defaultCssFile; | ||
$this->twig = $twig; | ||
} | ||
|
||
public function getDefaultCss(): string | ||
{ | ||
return $this->twig->render($this->defaultCssFile); | ||
} | ||
} |
Oops, something went wrong.