LegacyExecutionContextFactory.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. * @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. /**
  27. * @var MetadataFactoryInterface
  28. */
  29. private $metadataFactory;
  30. /**
  31. * @var TranslatorInterface
  32. */
  33. private $translator;
  34. /**
  35. * @var string|null
  36. */
  37. private $translationDomain;
  38. /**
  39. * Creates a new context factory.
  40. *
  41. * @param MetadataFactoryInterface $metadataFactory The metadata factory
  42. * @param TranslatorInterface $translator The translator
  43. * @param string|null $translationDomain The translation domain
  44. * to use for translating
  45. * violation messages
  46. */
  47. public function __construct(MetadataFactoryInterface $metadataFactory, TranslatorInterface $translator, $translationDomain = null)
  48. {
  49. $this->metadataFactory = $metadataFactory;
  50. $this->translator = $translator;
  51. $this->translationDomain = $translationDomain;
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function createContext(ValidatorInterface $validator, $root)
  57. {
  58. return new LegacyExecutionContext(
  59. $validator,
  60. $root,
  61. $this->metadataFactory,
  62. $this->translator,
  63. $this->translationDomain
  64. );
  65. }
  66. }