-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 2.1: Generate changelog for v2.1.0-ALPHA.1 [Debug] Adjust CLI namespace and its configuration CS fixes PR review fixes [Testing] Making integration tests more generic [Maintenance] Test integration with translation component [DX] Improve mail dumper CS fixes Refactor command parts to separate services Replace hardcoded path with template loader Test DebugMailerCommand Debug mailer command PoC
- Loading branch information
Showing
19 changed files
with
486 additions
and
6 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
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,69 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\MailerBundle\Console\Command; | ||
|
||
use Sylius\Bundle\MailerBundle\Console\Command\Dumper\DumperInterface; | ||
use Sylius\Bundle\MailerBundle\Console\Command\Dumper\EmailDetailDumperInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
#[AsCommand(name: 'sylius:debug:mailer', description: 'Debug email messages')] | ||
final class DebugMailerCommand extends Command | ||
{ | ||
public function __construct( | ||
/** @var DumperInterface[] $dumpers */ | ||
private readonly iterable $dumpers, | ||
private readonly EmailDetailDumperInterface $emailDetailDumper, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this->addArgument('codeOfEmail', InputArgument::OPTIONAL, 'Expected email to be shown identified by its code'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
if ($input->getArgument('codeOfEmail') === null) { | ||
return $this->dumpAllEmails($input, $output); | ||
} | ||
|
||
return $this->dumpEmailDetails($input, $output); | ||
} | ||
|
||
private function dumpAllEmails(InputInterface $input, OutputInterface $output): int | ||
{ | ||
foreach ($this->dumpers as $dumper) { | ||
$dumper->dump($input, $output); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
private function dumpEmailDetails(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$codeOfEmail = $input->getArgument('codeOfEmail'); | ||
|
||
Assert::string($codeOfEmail); | ||
|
||
$this->emailDetailDumper->dump($codeOfEmail, $input, $output); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
interface DumperInterface | ||
{ | ||
public function dump(InputInterface $input, OutputInterface $output): void; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Bundle/Console/Command/Dumper/EmailDetailDumperInterface.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,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
interface EmailDetailDumperInterface | ||
{ | ||
public function dump(string $code, InputInterface $input, OutputInterface $output): void; | ||
} |
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,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
use Twig\Loader\LoaderInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class EmailDetailsDumper implements EmailDetailDumperInterface | ||
{ | ||
public function __construct( | ||
private readonly array $emails, | ||
private readonly ?TranslatorInterface $translator, | ||
private readonly LoaderInterface $templateLoader, | ||
) { | ||
} | ||
|
||
public function dump(string $code, InputInterface $input, OutputInterface $output): void | ||
{ | ||
$email = $this->emails[$code]; | ||
|
||
Assert::notNull($email, sprintf('Email with code "%s" does not exist.', $code)); | ||
|
||
$subject = $email['subject'] ?? ''; | ||
|
||
if ($this->translator !== null) { | ||
$subject = $this->translator->trans($subject); | ||
} | ||
|
||
$io = new SymfonyStyle($input, $output); | ||
$io->title(sprintf('<fg=cyan>Email:</> %s', $code)); | ||
$io->writeln(sprintf('<comment>Subject:</comment> %s', $subject)); | ||
$io->writeln(sprintf('<comment>Enabled:</comment> %s', $email['enabled'] ? '<info>yes</info>' : '<error>no</error>')); | ||
$io->newLine(); | ||
$io->text($this->templateLoader->getSourceContext($email['template'])->getCode()); | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper; | ||
|
||
use Symfony\Component\Console\Helper\Table; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
final class EmailsListDumper implements DumperInterface | ||
{ | ||
public function __construct( | ||
private readonly array $emails, | ||
private readonly ?TranslatorInterface $translator, | ||
) { | ||
} | ||
|
||
public function dump(InputInterface $input, OutputInterface $output): void | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
$rows = []; | ||
|
||
foreach ($this->emails as $code => $emailConfiguration) { | ||
$subject = $emailConfiguration['subject'] ?? ''; | ||
|
||
if ($this->translator !== null) { | ||
$subject = $this->translator->trans($subject); | ||
} | ||
|
||
$rows[] = [ | ||
$code, | ||
$emailConfiguration['template'], | ||
$emailConfiguration['enabled'] ? 'yes' : 'no', | ||
$subject, | ||
]; | ||
} | ||
|
||
$io->section('<info>Emails</info>'); | ||
|
||
$table = new Table($output); | ||
$table->setHeaders(['Code', 'Template', 'Enabled', 'Subject']); | ||
$table->setRows($rows); | ||
$table->render(); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\MailerBundle\Console\Command\Dumper; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class SenderDataDumper implements DumperInterface | ||
{ | ||
public function __construct( | ||
private readonly string $senderName, | ||
private readonly string $senderEmail, | ||
) { | ||
} | ||
|
||
public function dump(InputInterface $input, OutputInterface $output): void | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$io->section('<info>Sender</info>'); | ||
$io->horizontalTable(['Name', 'Email'], [[$this->senderName, $this->senderEmail]]); | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
src/Bundle/test/config/packages/test_with_translations/framework.yaml
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,3 @@ | ||
framework: | ||
translator: | ||
default_path: '%kernel.project_dir%/translations' |
3 changes: 3 additions & 0 deletions
3
src/Bundle/test/config/packages/test_with_translations/mailer.yaml
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,3 @@ | ||
framework: | ||
mailer: | ||
dsn: 'null://null' |
17 changes: 17 additions & 0 deletions
17
src/Bundle/test/config/packages/test_with_translations/sylius_mailer.yaml
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,17 @@ | ||
sylius_mailer: | ||
sender: | ||
name: Sender | ||
address: [email protected] | ||
sender_adapter: sylius.email_sender.adapter.symfony_mailer | ||
emails: | ||
test_email: | ||
subject: 'Hardcoded subject' | ||
template: 'Email/test.html.twig' | ||
test_email_with_data: | ||
subject: 'sylius_mailer.test_email_with_data.subject' | ||
template: 'Email/testWithData.html.twig' | ||
test_modified_email: | ||
template: 'Email/test.html.twig' | ||
test_disabled_email: | ||
template: 'Email/test.html.twig' | ||
enabled: false |
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,3 @@ | ||
sylius_mailer: | ||
test_email_with_data: | ||
subject: Subject for email with data |
Oops, something went wrong.