src/Model/Email.php line 17

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Model;
  4. use App\Validator as AppAssert;
  5. use OpenApi\Annotations as OA;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. /**
  8.  * @OA\Schema(
  9.  *     schema="Email",
  10.  *     required={"templatePath", "to"}
  11.  *  )
  12.  */
  13. class Email
  14. {
  15.     public const DEFAULT_FROM 'console';
  16.     public const DEFAULT_FROM_NAME 'HiPay';
  17.     /**
  18.      * @OA\Property(
  19.      *      type="string",
  20.      *      description="The path of a template that you would like to use.",
  21.      *      example="account-api/hello"
  22.      * )
  23.      *
  24.      * @var string
  25.      * @AppAssert\TemplatePath()
  26.      */
  27.     #[Assert\NotBlank]
  28.     private $templatePath;
  29.     /**
  30.      * @OA\Property(
  31.      *      type="object",
  32.      *      description="Template variables, expecting : {""firstname"": ""John"", ""lastname"": ""Doe""}",
  33.      *      @OA\Property(property="key", type="string", example="value")
  34.      * )
  35.      *
  36.      * @AppAssert\TemplateData()
  37.      *
  38.      * @var array
  39.      */
  40.     private $templateData = [];
  41.     /**
  42.      * @OA\Property(
  43.      *      type="string",
  44.      *      description="The subject of your email"
  45.      * )
  46.      *
  47.      * @var string
  48.      */
  49.     #[Assert\Type('string')]
  50.     #[Assert\Length(min1max255)]
  51.     private $subject;
  52.     /**
  53.      * @OA\Property(
  54.      *     type="string",
  55.      *     description="The email local-part",
  56.      *     example="console"
  57.      * )
  58.      *
  59.      * @var string
  60.      */
  61.     #[Assert\NotBlank]
  62.     #[Assert\Type('string')]
  63.     #[Assert\Regex('/^[0-9A-Za-z-+.]+$/'message'Invalid email local-part, provide a value without @domain.tld')]
  64.     private $from self::DEFAULT_FROM;
  65.     /**
  66.      * @OA\Property(
  67.      *     type="string",
  68.      *     description="The email display name",
  69.      *     example="HiPay"
  70.      * )
  71.      *
  72.      * @var string
  73.      */
  74.     #[Assert\NotBlank]
  75.     #[Assert\Type('string')]
  76.     private $fromName self::DEFAULT_FROM_NAME;
  77.     /**
  78.      * @OA\Property(
  79.      *      type="array",
  80.      *      description="An array of repliers, ex: [""[email protected]"", ""Jane Doe <[email protected]>""]",
  81.      *      @OA\Items(type="string",  example="[email protected]")
  82.      * )
  83.      * @var array
  84.      */
  85.     #[Assert\Type('array')]
  86.     #[Assert\Count(max1000maxMessage'You cannot specify more than {{ limit }} emails')]
  87.     #[Assert\All([new Assert\NotBlank(), new Assert\Type('string'), new AppAssert\EmailAddress()])]
  88.     private $reply = [];
  89.     /**
  90.      * @OA\Property(
  91.      *      type="array",
  92.      *      description="An array of recipients, ex: [""[email protected]"", ""Jane Doe <[email protected]>""]",
  93.      *      @OA\Items(type="string",  example="[email protected]")
  94.      * )
  95.      * @var array
  96.      */
  97.     #[Assert\NotBlank]
  98.     #[Assert\Type('array')]
  99.     #[Assert\Count(min1max1000minMessage'You must specify at least one email'maxMessage'You cannot specify more than {{ limit }} emails')]
  100.     #[Assert\All([new Assert\NotBlank(), new Assert\Type('string'), new AppAssert\EmailAddress()])]
  101.     private $to = [];
  102.     /**
  103.      * @OA\Property(
  104.      *      type="array",
  105.      *      description="An array of recipients, ex: [""[email protected]"", ""Jane Doe <[email protected]>""]",
  106.      *      @OA\Items(type="string",  example="[email protected]")
  107.      * )
  108.      * @var array
  109.      */
  110.     #[Assert\Type('array')]
  111.     #[Assert\Count(max1000maxMessage'You cannot specify more than {{ limit }} emails')]
  112.     #[Assert\All([new Assert\NotBlank(), new Assert\Type('string'), new AppAssert\EmailAddress()])]
  113.     private $cc = [];
  114.     /**
  115.      * @OA\Property(
  116.      *      type="array",
  117.      *      description="An array of recipients, ex: [""[email protected]"", ""Jane Doe <[email protected]>""]",
  118.      *      @OA\Items(type="string",  example="[email protected]")
  119.      * )
  120.      * @var array
  121.      */
  122.     #[Assert\Type('array')]
  123.     #[Assert\Count(max1000maxMessage'You cannot specify more than {{ limit }} emails')]
  124.     #[Assert\All([new Assert\NotBlank(), new Assert\Type('string'), new AppAssert\EmailAddress()])]
  125.     private $bcc = [];
  126.     /**
  127.      * @OA\Property(
  128.      *      type="array",
  129.      *      description="An array of objects in which you can specify any attachments you want to include.",
  130.      *      @OA\Items(
  131.      *          required={"filename", "contentType", "content"},
  132.      *          @OA\Property(
  133.      *              property="filename",
  134.      *              type="string",
  135.      *              description="The filename of the attachment.",
  136.      *              example="filename.pdf",
  137.      *          ),
  138.      *          @OA\Property(
  139.      *              property="contentType",
  140.      *              type="string",
  141.      *              description="The content type of the attachment (ex: image/jpeg).",
  142.      *          ),
  143.      *          @OA\Property(
  144.      *              property="content",
  145.      *              type="string",
  146.      *              description="The Base64 encoded content of the attachment.",
  147.      *          )
  148.      *      ),
  149.      * ),
  150.      *
  151.      * @var array
  152.      */
  153.     #[Assert\All([new Assert\Collection(fields: ['filename' => [new Assert\NotBlank(), new Assert\Type('string')], 'contentType' => [new Assert\NotBlank(), new Assert\Type('string')], 'content' => [new Assert\NotBlank(), new Assert\Type('string')]], allowMissingFieldsfalseallowExtraFieldsfalse)])]
  154.     private $attachments;
  155.     /**
  156.      * @OA\Property(
  157.      *      type="string",
  158.      *      description="Set the locale for the email template",
  159.      *      example="fr_FR"
  160.      * )
  161.      *
  162.      * @var string
  163.      */
  164.     #[Assert\Locale]
  165.     private $locale;
  166.     /**
  167.      * @OA\Property(
  168.      *      type="boolean",
  169.      *      description="Prevent sending the mail and view debug info",
  170.      *      example=true
  171.      * )
  172.      *
  173.      * @var bool
  174.      */
  175.     #[Assert\Type('boolean')]
  176.     private $debug false;
  177.     /**
  178.      * @return array
  179.      */
  180.     public function getTo(): array
  181.     {
  182.         return $this->to;
  183.     }
  184.     /**
  185.      * @param array $to
  186.      */
  187.     public function setTo(array $to): void
  188.     {
  189.         $this->to $to;
  190.     }
  191.     /**
  192.      * @return string
  193.      */
  194.     public function getTemplatePath(): string
  195.     {
  196.         return $this->templatePath;
  197.     }
  198.     /**
  199.      * @param string $templatePath
  200.      */
  201.     public function setTemplatePath(string $templatePath): void
  202.     {
  203.         $this->templatePath $templatePath;
  204.     }
  205.     /**
  206.      * @return array
  207.      */
  208.     public function getTemplateData(): array
  209.     {
  210.         return $this->templateData;
  211.     }
  212.     /**
  213.      * @param array $templateData
  214.      */
  215.     public function setTemplateData(array $templateData): void
  216.     {
  217.         $this->templateData $templateData;
  218.     }
  219.     /**
  220.      * @return string
  221.      */
  222.     public function getSubject(): ?string
  223.     {
  224.         return $this->subject;
  225.     }
  226.     /**
  227.      * @param string $subject
  228.      */
  229.     public function setSubject(string $subject): void
  230.     {
  231.         $this->subject $subject;
  232.     }
  233.     /**
  234.      * @return string
  235.      */
  236.     public function getFrom(): string
  237.     {
  238.         return $this->from;
  239.     }
  240.     /**
  241.      * @param string $from
  242.      */
  243.     public function setFrom(string $from): void
  244.     {
  245.         $this->from $from;
  246.     }
  247.     /**
  248.      * @return string
  249.      */
  250.     public function getFromName(): string
  251.     {
  252.         return $this->fromName;
  253.     }
  254.     /**
  255.      * @param string $fromName
  256.      */
  257.     public function setFromName(string $fromName): void
  258.     {
  259.         $this->fromName $fromName;
  260.     }
  261.     /**
  262.      * @return array
  263.      */
  264.     public function getReply(): array
  265.     {
  266.         return $this->reply;
  267.     }
  268.     /**
  269.      * @param array $reply
  270.      */
  271.     public function setReply(array $reply): void
  272.     {
  273.         $this->reply $reply;
  274.     }
  275.     /**
  276.      * @return array
  277.      */
  278.     public function getCc(): array
  279.     {
  280.         return $this->cc;
  281.     }
  282.     /**
  283.      * @param array $cc
  284.      */
  285.     public function setCc(array $cc): void
  286.     {
  287.         $this->cc $cc;
  288.     }
  289.     /**
  290.      * @return array
  291.      */
  292.     public function getBcc(): array
  293.     {
  294.         return $this->bcc;
  295.     }
  296.     /**
  297.      * @param array $bcc
  298.      */
  299.     public function setBcc(array $bcc): void
  300.     {
  301.         $this->bcc $bcc;
  302.     }
  303.     /**
  304.      * @return array
  305.      */
  306.     public function getAttachments(): ?array
  307.     {
  308.         return $this->attachments;
  309.     }
  310.     /**
  311.      * @param array $attachments
  312.      */
  313.     public function setAttachments(array $attachments): void
  314.     {
  315.         $this->attachments $attachments;
  316.     }
  317.     /**
  318.      * @return string
  319.      */
  320.     public function getLocale(): ?string
  321.     {
  322.         return $this->locale;
  323.     }
  324.     /**
  325.      * @param string $locale
  326.      */
  327.     public function setLocale(string $locale): void
  328.     {
  329.         $this->locale $locale;
  330.     }
  331.     /**
  332.      * @return bool
  333.      */
  334.     public function isDebug(): bool
  335.     {
  336.         return $this->debug;
  337.     }
  338.     /**
  339.      * @param bool $debug
  340.      */
  341.     public function setDebug(bool $debug): void
  342.     {
  343.         $this->debug $debug;
  344.     }
  345. }