Skip to content

Commit 68ac282

Browse files
committed
TemplateLinkValidator
1 parent 0430c35 commit 68ac282

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

resources/translations/messages.en.xlf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,12 @@
374374
<target>Image "%url%" could not be validated: %message%</target>
375375
</trans-unit>
376376

377+
<trans-unit id="messaging.validation.urls_not_full">
378+
<source>Not full URLs: %urls%</source>
379+
<target>Not full URLs: %urls%</target>
380+
</trans-unit>
381+
382+
377383
<!-- Subscription -->
378384
<trans-unit id="subscription.list_not_found">
379385
<source>Subscriber list not found.</source>
@@ -389,7 +395,6 @@
389395
<source>Subscription not found for this subscriber and list.</source>
390396
<target>Subscription not found for this subscriber and list.</target>
391397
</trans-unit>
392-
393398
</body>
394399
</file>
395400
</xliff>

src/Domain/Messaging/Validator/TemplateLinkValidator.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
use PhpList\Core\Domain\Common\Model\ValidationContext;
99
use PhpList\Core\Domain\Common\Validator\ValidatorInterface;
1010
use Symfony\Component\Validator\Exception\ValidatorException;
11+
use Symfony\Contracts\Translation\TranslatorInterface;
1112

1213
class TemplateLinkValidator implements ValidatorInterface
1314
{
15+
public function __construct(private readonly TranslatorInterface $translator)
16+
{
17+
}
18+
1419
private const PLACEHOLDERS = [
1520
'[PREFERENCESURL]',
1621
'[UNSUBSCRIBEURL]',
@@ -37,10 +42,9 @@ public function validate(mixed $value, ValidationContext $context = null): void
3742
}
3843

3944
if (!empty($invalid)) {
40-
throw new ValidatorException(sprintf(
41-
'Not full URLs: %s',
42-
implode(', ', $invalid)
43-
));
45+
throw new ValidatorException(
46+
$this->translator->trans('Not full URLs: %urls%', ['%urls%' => implode(', ', $invalid)]),
47+
);
4448
}
4549
}
4650

tests/Unit/Domain/Messaging/Validator/TemplateLinkValidatorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpList\Core\Domain\Common\Model\ValidationContext;
88
use PhpList\Core\Domain\Messaging\Validator\TemplateLinkValidator;
99
use PHPUnit\Framework\TestCase;
10+
use Symfony\Component\Translation\Translator;
1011
use Symfony\Component\Validator\Exception\ValidatorException;
1112

1213
class TemplateLinkValidatorTest extends TestCase
@@ -15,7 +16,7 @@ class TemplateLinkValidatorTest extends TestCase
1516

1617
protected function setUp(): void
1718
{
18-
$this->validator = new TemplateLinkValidator();
19+
$this->validator = new TemplateLinkValidator(new Translator('en'));
1920
}
2021

2122
public function testSkipsValidationIfNotString(): void

0 commit comments

Comments
 (0)