LegacyExecutionContextFactory.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 version 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. * @since 2.5
  21. *
  22. * @author Bernhard Schussek <bschussek@gmail.com>
  23. *
  24. * @deprecated since version 2.5, to be removed in 3.0.
  25. */
  26. class LegacyExecutionContextFactory implements ExecutionContextFactoryInterface
  27. {
  28. /**
  29. * @var MetadataFactoryInterface
  30. */
  31. private $metadataFactory;
  32. /**
  33. * @var TranslatorInterface
  34. */
  35. private $translator;
  36. /**
  37. * @var string|null
  38. */
  39. private $translationDomain;
  40. /**
  41. * Creates a new context factory.
  42. *
  43. * @param MetadataFactoryInterface $metadataFactory The metadata factory
  44. * @param TranslatorInterface $translator The translator
  45. * @param string|null $translationDomain The translation domain
  46. * to use for translating
  47. * violation messages
  48. */
  49. public function __construct(MetadataFactoryInterface $metadataFactory, TranslatorInterface $translator, $translationDomain = null)
  50. {
  51. $this->metadataFactory = $metadataFactory;
  52. $this->translator = $translator;
  53. $this->translationDomain = $translationDomain;
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function createContext(ValidatorInterface $validator, $root)
  59. {
  60. return new LegacyExecutionContext(
  61. $validator,
  62. $root,
  63. $this->metadataFactory,
  64. $this->translator,
  65. $this->translationDomain
  66. );
  67. }
  68. }