34 lines
889 B
PHP
34 lines
889 B
PHP
<?php
|
|
|
|
namespace App\Validator;
|
|
|
|
use Symfony\Component\Validator\Constraint;
|
|
|
|
/**
|
|
* Rejects {tokens} the mail being edited does not know.
|
|
*
|
|
* Without this a typo like {destinaton} would reach a teamer's inbox as a literal token
|
|
* or, worse, silently as a dash.
|
|
*/
|
|
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
|
|
class KnownPlaceholders extends Constraint
|
|
{
|
|
public string $message = 'Unbekannter Platzhalter: {{ placeholder }}. Erlaubt sind: {{ allowed }}';
|
|
|
|
/**
|
|
* @var string[]
|
|
*/
|
|
public array $allowed = [];
|
|
|
|
/**
|
|
* @param string[] $allowed
|
|
*/
|
|
public function __construct(array $allowed = [], ?string $message = null, ?array $groups = null, mixed $payload = null)
|
|
{
|
|
parent::__construct(null, $groups, $payload);
|
|
|
|
$this->allowed = $allowed;
|
|
$this->message = $message ?? $this->message;
|
|
}
|
|
}
|