vendor/symfony/translation/TranslatableMessage.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Translation;
  11. use Symfony\Contracts\Translation\TranslatableInterface;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. /**
  14.  * @author Nate Wiebe <nate@northern.co>
  15.  */
  16. class TranslatableMessage implements TranslatableInterface
  17. {
  18.     private string $message;
  19.     private array $parameters;
  20.     private ?string $domain;
  21.     public function __construct(string $message, array $parameters = [], string $domain null)
  22.     {
  23.         $this->message $message;
  24.         $this->parameters $parameters;
  25.         $this->domain $domain;
  26.     }
  27.     public function __toString(): string
  28.     {
  29.         return $this->getMessage();
  30.     }
  31.     public function getMessage(): string
  32.     {
  33.         return $this->message;
  34.     }
  35.     public function getParameters(): array
  36.     {
  37.         return $this->parameters;
  38.     }
  39.     public function getDomain(): ?string
  40.     {
  41.         return $this->domain;
  42.     }
  43.     public function trans(TranslatorInterface $translatorstring $locale null): string
  44.     {
  45.         return $translator->trans($this->getMessage(), array_map(
  46.             static function ($parameter) use ($translator$locale) {
  47.                 return $parameter instanceof TranslatableInterface $parameter->trans($translator$locale) : $parameter;
  48.             },
  49.             $this->getParameters()
  50.         ), $this->getDomain(), $locale);
  51.     }
  52. }