You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/OptionsResolver.php
+42-18Lines changed: 42 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -103,6 +103,8 @@ class OptionsResolver implements Options
103
103
*/
104
104
private$locked = false;
105
105
106
+
private$parentsOptions = [];
107
+
106
108
privatestatic$typeAliases = [
107
109
'boolean' => 'bool',
108
110
'integer' => 'int',
@@ -423,7 +425,7 @@ public function setDeprecated(string $option, $deprecationMessage = 'The option
423
425
}
424
426
425
427
if (!isset($this->defined[$option])) {
426
-
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist, defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
428
+
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist, defined options are: "%s".', $this->formatOptionsForAnException($option), implode('", "', array_keys($this->defined))));
427
429
}
428
430
429
431
if (!\is_string($deprecationMessage) && !$deprecationMessageinstanceof \Closure) {
@@ -481,7 +483,7 @@ public function setNormalizer($option, \Closure $normalizer)
481
483
}
482
484
483
485
if (!isset($this->defined[$option])) {
484
-
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
486
+
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptionsForAnException($option), implode('", "', array_keys($this->defined))));
485
487
}
486
488
487
489
$this->normalizers[$option] = [$normalizer];
@@ -526,7 +528,7 @@ public function addNormalizer(string $option, \Closure $normalizer, bool $forceP
526
528
}
527
529
528
530
if (!isset($this->defined[$option])) {
529
-
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
531
+
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptionsForAnException($option), implode('", "', array_keys($this->defined))));
530
532
}
531
533
532
534
if ($forcePrepend) {
@@ -569,7 +571,7 @@ public function setAllowedValues($option, $allowedValues)
569
571
}
570
572
571
573
if (!isset($this->defined[$option])) {
572
-
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
574
+
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptionsForAnException($option), implode('", "', array_keys($this->defined))));
@@ -610,7 +612,7 @@ public function addAllowedValues($option, $allowedValues)
610
612
}
611
613
612
614
if (!isset($this->defined[$option])) {
613
-
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
615
+
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptionsForAnException($option), implode('", "', array_keys($this->defined))));
614
616
}
615
617
616
618
if (!\is_array($allowedValues)) {
@@ -651,7 +653,7 @@ public function setAllowedTypes($option, $allowedTypes)
651
653
}
652
654
653
655
if (!isset($this->defined[$option])) {
654
-
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
656
+
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptionsForAnException($option), implode('", "', array_keys($this->defined))));
@@ -686,7 +688,7 @@ public function addAllowedTypes($option, $allowedTypes)
686
688
}
687
689
688
690
if (!isset($this->defined[$option])) {
689
-
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
691
+
thrownewUndefinedOptionsException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptionsForAnException($option), implode('", "', array_keys($this->defined))));
690
692
}
691
693
692
694
if (!isset($this->allowedTypes[$option])) {
@@ -793,7 +795,7 @@ public function resolve(array $options = [])
793
795
ksort($clone->defined);
794
796
ksort($diff);
795
797
796
-
thrownewUndefinedOptionsException(sprintf((\count($diff) > 1 ? 'The options "%s" do not exist.' : 'The option "%s" does not exist.').' Defined options are: "%s".', implode('", "', array_keys($diff)), implode('", "', array_keys($clone->defined))));
798
+
thrownewUndefinedOptionsException(sprintf((\count($diff) > 1 ? 'The options "%s" do not exist.' : 'The option "%s" does not exist.').' Defined options are: "%s".', $this->formatOptionsForAnException(array_keys($diff)), implode('", "', array_keys($clone->defined))));
797
799
}
798
800
799
801
// Override options set by the user
@@ -809,7 +811,7 @@ public function resolve(array $options = [])
809
811
if (\count($diff) > 0) {
810
812
ksort($diff);
811
813
812
-
thrownewMissingOptionsException(sprintf(\count($diff) > 1 ? 'The required options "%s" are missing.' : 'The required option "%s" is missing.', implode('", "', array_keys($diff))));
814
+
thrownewMissingOptionsException(sprintf(\count($diff) > 1 ? 'The required options "%s" are missing.' : 'The required option "%s" is missing.', $this->formatOptionsForAnException(array_keys($diff))));
813
815
}
814
816
815
817
// Lock the container
@@ -860,10 +862,10 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
860
862
// Check whether the option is set at all
861
863
if (!isset($this->defaults[$option]) && !\array_key_exists($option, $this->defaults)) {
862
864
if (!isset($this->defined[$option])) {
863
-
thrownewNoSuchOptionException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $option, implode('", "', array_keys($this->defined))));
865
+
thrownewNoSuchOptionException(sprintf('The option "%s" does not exist. Defined options are: "%s".', $this->formatOptionsForAnException($option), implode('", "', array_keys($this->defined))));
864
866
}
865
867
866
-
thrownewNoSuchOptionException(sprintf('The optional option "%s" has no value set. You should make sure it is set with "isset" before reading it.', $option));
868
+
thrownewNoSuchOptionException(sprintf('The optional option "%s" has no value set. You should make sure it is set with "isset" before reading it.', $this->formatOptionsForAnException($option)));
867
869
}
868
870
869
871
$value = $this->defaults[$option];
@@ -872,17 +874,19 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
872
874
if (isset($this->nested[$option])) {
873
875
// If the closure is already being called, we have a cyclic dependency
874
876
if (isset($this->calling[$option])) {
875
-
thrownewOptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', implode('", "', array_keys($this->calling))));
877
+
thrownewOptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', $this->formatOptionsForAnException(array_keys($this->calling))));
876
878
}
877
879
878
880
if (!\is_array($value)) {
879
-
thrownewInvalidOptionsException(sprintf('The nested option "%s" with value %s is expected to be of type array, but is of type "%s".', $option, $this->formatValue($value), $this->formatTypeOf($value)));
881
+
thrownewInvalidOptionsException(sprintf('The nested option "%s" with value %s is expected to be of type array, but is of type "%s".', $this->formatOptionsForAnException($option), $this->formatValue($value), $this->formatTypeOf($value)));
880
882
}
881
883
882
884
// The following section must be protected from cyclic calls.
@@ -897,7 +901,7 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
897
901
// If the closure is already being called, we have a cyclic
898
902
// dependency
899
903
if (isset($this->calling[$option])) {
900
-
thrownewOptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', implode('", "', array_keys($this->calling))));
904
+
thrownewOptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', $this->formatOptionsForAnException(array_keys($this->calling))));
901
905
}
902
906
903
907
// The following section must be protected from cyclic
@@ -932,10 +936,10 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
932
936
$keys = array_keys($invalidTypes);
933
937
934
938
if (1 === \count($keys) && '[]' === substr($keys[0], -2)) {
935
-
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but one of the elements is of type "%s".', $option, $this->formatValue($value), implode('" or "', $this->allowedTypes[$option]), $keys[0]));
939
+
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but one of the elements is of type "%s".', $this->formatOptionsForAnException($option), $this->formatValue($value), implode('" or "', $this->allowedTypes[$option]), $keys[0]));
936
940
}
937
941
938
-
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but is of type "%s".', $option, $this->formatValue($value), implode('" or "', $this->allowedTypes[$option]), implode('|', array_keys($invalidTypes))));
942
+
thrownewInvalidOptionsException(sprintf('The option "%s" with value %s is expected to be of type "%s", but is of type "%s".', $this->formatOptionsForAnException($option), $this->formatValue($value), implode('" or "', $this->allowedTypes[$option]), implode('|', array_keys($invalidTypes))));
939
943
}
940
944
}
941
945
@@ -989,7 +993,7 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
989
993
if ($deprecationMessageinstanceof \Closure) {
990
994
// If the closure is already being called, we have a cyclic dependency
991
995
if (isset($this->calling[$option])) {
992
-
thrownewOptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', implode('", "', array_keys($this->calling))));
996
+
thrownewOptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', $this->formatOptionsForAnException(array_keys($this->calling))));
993
997
}
994
998
995
999
$this->calling[$option] = true;
@@ -1012,7 +1016,7 @@ public function offsetGet($option/*, bool $triggerDeprecation = true*/)
1012
1016
// If the closure is already being called, we have a cyclic
1013
1017
// dependency
1014
1018
if (isset($this->calling[$option])) {
1015
-
thrownewOptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', implode('", "', array_keys($this->calling))));
1019
+
thrownewOptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', $this->formatOptionsForAnException(array_keys($this->calling))));
1016
1020
}
1017
1021
1018
1022
// The following section must be protected from cyclic
@@ -1195,4 +1199,24 @@ private function formatValues(array $values): string
0 commit comments