validator.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\DependencyInjection\Loader\Configurator;
  11. use Symfony\Bundle\FrameworkBundle\CacheWarmer\ValidatorCacheWarmer;
  12. use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
  13. use Symfony\Component\Validator\Constraints\EmailValidator;
  14. use Symfony\Component\Validator\Constraints\ExpressionValidator;
  15. use Symfony\Component\Validator\Constraints\NotCompromisedPasswordValidator;
  16. use Symfony\Component\Validator\ContainerConstraintValidatorFactory;
  17. use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
  18. use Symfony\Component\Validator\Validation;
  19. use Symfony\Component\Validator\Validator\ValidatorInterface;
  20. use Symfony\Component\Validator\ValidatorBuilder;
  21. return static function (ContainerConfigurator $container) {
  22. $container->parameters()
  23. ->set('validator.mapping.cache.file', param('kernel.cache_dir').'/validation.php');
  24. $container->services()
  25. ->set('validator', ValidatorInterface::class)
  26. ->public()
  27. ->factory([service('validator.builder'), 'getValidator'])
  28. ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2'])
  29. ->alias(ValidatorInterface::class, 'validator')
  30. ->set('validator.builder', ValidatorBuilder::class)
  31. ->factory([Validation::class, 'createValidatorBuilder'])
  32. ->call('setConstraintValidatorFactory', [
  33. service('validator.validator_factory'),
  34. ])
  35. ->call('setTranslator', [
  36. service('translator')->ignoreOnInvalid(),
  37. ])
  38. ->call('setTranslationDomain', [
  39. param('validator.translation_domain'),
  40. ])
  41. ->alias('validator.mapping.class_metadata_factory', 'validator')
  42. ->set('validator.mapping.cache_warmer', ValidatorCacheWarmer::class)
  43. ->args([
  44. service('validator.builder'),
  45. param('validator.mapping.cache.file'),
  46. ])
  47. ->tag('kernel.cache_warmer')
  48. ->set('validator.mapping.cache.adapter', PhpArrayAdapter::class)
  49. ->factory([PhpArrayAdapter::class, 'create'])
  50. ->args([
  51. param('validator.mapping.cache.file'),
  52. service('cache.validator'),
  53. ])
  54. ->set('validator.validator_factory', ContainerConstraintValidatorFactory::class)
  55. ->args([
  56. abstract_arg('Constraint validators locator'),
  57. ])
  58. ->set('validator.expression', ExpressionValidator::class)
  59. ->tag('validator.constraint_validator', [
  60. 'alias' => 'validator.expression',
  61. ])
  62. ->set('validator.email', EmailValidator::class)
  63. ->args([
  64. abstract_arg('Default mode'),
  65. ])
  66. ->tag('validator.constraint_validator', [
  67. 'alias' => EmailValidator::class,
  68. ])
  69. ->set('validator.not_compromised_password', NotCompromisedPasswordValidator::class)
  70. ->args([
  71. service('http_client')->nullOnInvalid(),
  72. param('kernel.charset'),
  73. false,
  74. ])
  75. ->tag('validator.constraint_validator', [
  76. 'alias' => NotCompromisedPasswordValidator::class,
  77. ])
  78. ->set('validator.property_info_loader', PropertyInfoLoader::class)
  79. ->args([
  80. service('property_info'),
  81. service('property_info'),
  82. service('property_info'),
  83. ])
  84. ->tag('validator.auto_mapper')
  85. ;
  86. };