OptionsResolverWrapper.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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\Form\Util;
  11. use Symfony\Component\OptionsResolver\Exception\AccessException;
  12. use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. /**
  15. * @author Yonel Ceruto <yonelceruto@gmail.com>
  16. *
  17. * @internal
  18. */
  19. class OptionsResolverWrapper extends OptionsResolver
  20. {
  21. private $undefined = [];
  22. /**
  23. * @return $this
  24. */
  25. public function setNormalizer(string $option, \Closure $normalizer): self
  26. {
  27. try {
  28. parent::setNormalizer($option, $normalizer);
  29. } catch (UndefinedOptionsException $e) {
  30. $this->undefined[$option] = true;
  31. }
  32. return $this;
  33. }
  34. /**
  35. * @return $this
  36. */
  37. public function setAllowedValues(string $option, $allowedValues): self
  38. {
  39. try {
  40. parent::setAllowedValues($option, $allowedValues);
  41. } catch (UndefinedOptionsException $e) {
  42. $this->undefined[$option] = true;
  43. }
  44. return $this;
  45. }
  46. /**
  47. * @return $this
  48. */
  49. public function addAllowedValues(string $option, $allowedValues): self
  50. {
  51. try {
  52. parent::addAllowedValues($option, $allowedValues);
  53. } catch (UndefinedOptionsException $e) {
  54. $this->undefined[$option] = true;
  55. }
  56. return $this;
  57. }
  58. /**
  59. * @return $this
  60. */
  61. public function setAllowedTypes(string $option, $allowedTypes): self
  62. {
  63. try {
  64. parent::setAllowedTypes($option, $allowedTypes);
  65. } catch (UndefinedOptionsException $e) {
  66. $this->undefined[$option] = true;
  67. }
  68. return $this;
  69. }
  70. /**
  71. * @return $this
  72. */
  73. public function addAllowedTypes(string $option, $allowedTypes): self
  74. {
  75. try {
  76. parent::addAllowedTypes($option, $allowedTypes);
  77. } catch (UndefinedOptionsException $e) {
  78. $this->undefined[$option] = true;
  79. }
  80. return $this;
  81. }
  82. public function resolve(array $options = []): array
  83. {
  84. throw new AccessException('Resolve options is not supported.');
  85. }
  86. public function getUndefinedOptions(): array
  87. {
  88. return array_keys($this->undefined);
  89. }
  90. }