ExecutionContextFactory.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Drupal\Core\TypedData\Validation;
  3. use Drupal\Core\Validation\TranslatorInterface;
  4. use Symfony\Component\Validator\Context\ExecutionContextFactoryInterface;
  5. use Symfony\Component\Validator\Validator\ValidatorInterface;
  6. /**
  7. * Defines an execution factory for the Typed Data validator.
  8. *
  9. * We do not use the factory provided by Symfony as it is marked internal.
  10. *
  11. * @codingStandardsIgnoreStart
  12. */
  13. class ExecutionContextFactory implements ExecutionContextFactoryInterface {
  14. /**
  15. * @var \Drupal\Core\Validation\TranslatorInterface
  16. */
  17. protected $translator;
  18. /**
  19. * @var string|null
  20. */
  21. protected $translationDomain;
  22. /**
  23. * Constructs a new ExecutionContextFactory instance.
  24. *
  25. * @param \Drupal\Core\Validation\TranslatorInterface $translator
  26. * The translator instance.
  27. * @param string $translationDomain
  28. * (optional) The translation domain.
  29. */
  30. public function __construct(TranslatorInterface $translator, $translationDomain = null)
  31. {
  32. $this->translator = $translator;
  33. $this->translationDomain = $translationDomain;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function createContext(ValidatorInterface $validator, $root)
  39. {
  40. return new ExecutionContext(
  41. $validator,
  42. $root,
  43. $this->translator,
  44. $this->translationDomain
  45. );
  46. }
  47. }