form.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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\Component\Form\ChoiceList\Factory\CachingFactoryDecorator;
  12. use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;
  13. use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
  14. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  15. use Symfony\Component\Form\Extension\Core\Type\ColorType;
  16. use Symfony\Component\Form\Extension\Core\Type\FileType;
  17. use Symfony\Component\Form\Extension\Core\Type\FormType;
  18. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  19. use Symfony\Component\Form\Extension\Core\Type\TransformationFailureExtension;
  20. use Symfony\Component\Form\Extension\DependencyInjection\DependencyInjectionExtension;
  21. use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
  22. use Symfony\Component\Form\Extension\HttpFoundation\Type\FormTypeHttpFoundationExtension;
  23. use Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension;
  24. use Symfony\Component\Form\Extension\Validator\Type\RepeatedTypeValidatorExtension;
  25. use Symfony\Component\Form\Extension\Validator\Type\SubmitTypeValidatorExtension;
  26. use Symfony\Component\Form\Extension\Validator\Type\UploadValidatorExtension;
  27. use Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser;
  28. use Symfony\Component\Form\FormFactory;
  29. use Symfony\Component\Form\FormFactoryInterface;
  30. use Symfony\Component\Form\FormRegistry;
  31. use Symfony\Component\Form\FormRegistryInterface;
  32. use Symfony\Component\Form\ResolvedFormTypeFactory;
  33. use Symfony\Component\Form\ResolvedFormTypeFactoryInterface;
  34. use Symfony\Component\Form\Util\ServerParams;
  35. return static function (ContainerConfigurator $container) {
  36. $container->services()
  37. ->set('form.resolved_type_factory', ResolvedFormTypeFactory::class)
  38. ->alias(ResolvedFormTypeFactoryInterface::class, 'form.resolved_type_factory')
  39. ->set('form.registry', FormRegistry::class)
  40. ->args([
  41. [
  42. /*
  43. * We don't need to be able to add more extensions.
  44. * more types can be registered with the form.type tag
  45. * more type extensions can be registered with the form.type_extension tag
  46. * more type_guessers can be registered with the form.type_guesser tag
  47. */
  48. service('form.extension'),
  49. ],
  50. service('form.resolved_type_factory'),
  51. ])
  52. ->alias(FormRegistryInterface::class, 'form.registry')
  53. ->set('form.factory', FormFactory::class)
  54. ->public()
  55. ->args([service('form.registry')])
  56. ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2'])
  57. ->alias(FormFactoryInterface::class, 'form.factory')
  58. ->set('form.extension', DependencyInjectionExtension::class)
  59. ->args([
  60. abstract_arg('All services with tag "form.type" are stored in a service locator by FormPass'),
  61. abstract_arg('All services with tag "form.type_extension" are stored here by FormPass'),
  62. abstract_arg('All services with tag "form.type_guesser" are stored here by FormPass'),
  63. ])
  64. ->set('form.type_guesser.validator', ValidatorTypeGuesser::class)
  65. ->args([service('validator.mapping.class_metadata_factory')])
  66. ->tag('form.type_guesser')
  67. ->alias('form.property_accessor', 'property_accessor')
  68. ->set('form.choice_list_factory.default', DefaultChoiceListFactory::class)
  69. ->set('form.choice_list_factory.property_access', PropertyAccessDecorator::class)
  70. ->args([
  71. service('form.choice_list_factory.default'),
  72. service('form.property_accessor'),
  73. ])
  74. ->set('form.choice_list_factory.cached', CachingFactoryDecorator::class)
  75. ->args([service('form.choice_list_factory.property_access')])
  76. ->tag('kernel.reset', ['method' => 'reset'])
  77. ->alias('form.choice_list_factory', 'form.choice_list_factory.cached')
  78. ->set('form.type.form', FormType::class)
  79. ->args([service('form.property_accessor')])
  80. ->tag('form.type')
  81. ->set('form.type.choice', ChoiceType::class)
  82. ->args([
  83. service('form.choice_list_factory'),
  84. service('translator')->ignoreOnInvalid(),
  85. ])
  86. ->tag('form.type')
  87. ->set('form.type.file', FileType::class)
  88. ->public()
  89. ->args([service('translator')->ignoreOnInvalid()])
  90. ->tag('form.type')
  91. ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2'])
  92. ->set('form.type.color', ColorType::class)
  93. ->args([service('translator')->ignoreOnInvalid()])
  94. ->tag('form.type')
  95. ->set('form.type_extension.form.transformation_failure_handling', TransformationFailureExtension::class)
  96. ->args([service('translator')->ignoreOnInvalid()])
  97. ->tag('form.type_extension', ['extended-type' => FormType::class])
  98. ->set('form.type_extension.form.http_foundation', FormTypeHttpFoundationExtension::class)
  99. ->args([service('form.type_extension.form.request_handler')])
  100. ->tag('form.type_extension')
  101. ->set('form.type_extension.form.request_handler', HttpFoundationRequestHandler::class)
  102. ->args([service('form.server_params')])
  103. ->set('form.server_params', ServerParams::class)
  104. ->args([service('request_stack')])
  105. ->set('form.type_extension.form.validator', FormTypeValidatorExtension::class)
  106. ->args([
  107. service('validator'),
  108. true,
  109. service('twig.form.renderer')->ignoreOnInvalid(),
  110. service('translator')->ignoreOnInvalid(),
  111. ])
  112. ->tag('form.type_extension', ['extended-type' => FormType::class])
  113. ->set('form.type_extension.repeated.validator', RepeatedTypeValidatorExtension::class)
  114. ->tag('form.type_extension')
  115. ->set('form.type_extension.submit.validator', SubmitTypeValidatorExtension::class)
  116. ->tag('form.type_extension', ['extended-type' => SubmitType::class])
  117. ->set('form.type_extension.upload.validator', UploadValidatorExtension::class)
  118. ->args([
  119. service('translator'),
  120. param('validator.translation_domain'),
  121. ])
  122. ->tag('form.type_extension')
  123. ;
  124. };