ExecutionContextFactory.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\Validator\Context;
  11. use Symfony\Component\Translation\TranslatorInterface;
  12. use Symfony\Component\Validator\Validator\ValidatorInterface;
  13. /**
  14. * Creates new {@link ExecutionContext} instances.
  15. *
  16. * @author Bernhard Schussek <bschussek@gmail.com>
  17. *
  18. * @internal You should not instantiate or use this class. Code against
  19. * {@link ExecutionContextFactoryInterface} instead.
  20. */
  21. class ExecutionContextFactory implements ExecutionContextFactoryInterface
  22. {
  23. private $translator;
  24. private $translationDomain;
  25. /**
  26. * Creates a new context factory.
  27. *
  28. * @param TranslatorInterface $translator The translator
  29. * @param string|null $translationDomain The translation domain to
  30. * use for translating
  31. * violation messages
  32. */
  33. public function __construct(TranslatorInterface $translator, $translationDomain = null)
  34. {
  35. $this->translator = $translator;
  36. $this->translationDomain = $translationDomain;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function createContext(ValidatorInterface $validator, $root)
  42. {
  43. return new ExecutionContext(
  44. $validator,
  45. $root,
  46. $this->translator,
  47. $this->translationDomain
  48. );
  49. }
  50. }