LegacyExecutionContextFactory.php 2.1 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. @trigger_error('The '.__NAMESPACE__.'\LegacyExecutionContextFactory class is deprecated since Symfony 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
  12. use Symfony\Component\Translation\TranslatorInterface;
  13. use Symfony\Component\Validator\MetadataFactoryInterface;
  14. use Symfony\Component\Validator\Validator\ValidatorInterface;
  15. /**
  16. * Creates new {@link LegacyExecutionContext} instances.
  17. *
  18. * Implemented for backward compatibility with Symfony < 2.5.
  19. *
  20. * @author Bernhard Schussek <bschussek@gmail.com>
  21. *
  22. * @deprecated since version 2.5, to be removed in 3.0.
  23. */
  24. class LegacyExecutionContextFactory implements ExecutionContextFactoryInterface
  25. {
  26. private $metadataFactory;
  27. private $translator;
  28. private $translationDomain;
  29. /**
  30. * Creates a new context factory.
  31. *
  32. * @param MetadataFactoryInterface $metadataFactory The metadata factory
  33. * @param TranslatorInterface $translator The translator
  34. * @param string|null $translationDomain The translation domain
  35. * to use for translating
  36. * violation messages
  37. */
  38. public function __construct(MetadataFactoryInterface $metadataFactory, TranslatorInterface $translator, $translationDomain = null)
  39. {
  40. $this->metadataFactory = $metadataFactory;
  41. $this->translator = $translator;
  42. $this->translationDomain = $translationDomain;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function createContext(ValidatorInterface $validator, $root)
  48. {
  49. return new LegacyExecutionContext(
  50. $validator,
  51. $root,
  52. $this->metadataFactory,
  53. $this->translator,
  54. $this->translationDomain
  55. );
  56. }
  57. }