ExecutionContextFactory.php 1.7 KB

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