14
14
use Symfony \Component \OptionsResolver \Exception \AccessException ;
15
15
use Symfony \Component \OptionsResolver \Exception \InvalidOptionsException ;
16
16
use Symfony \Component \OptionsResolver \Exception \MissingOptionsException ;
17
+ use Symfony \Component \OptionsResolver \Exception \NoSuchOptionException ;
17
18
use Symfony \Component \OptionsResolver \Exception \OptionDefinitionException ;
18
19
use Symfony \Component \OptionsResolver \Exception \UndefinedOptionsException ;
19
20
@@ -155,7 +156,7 @@ public function setDefault($option, $value)
155
156
// options could manipulate the state of the object, leading to
156
157
// inconsistent results.
157
158
if ($ this ->locked ) {
158
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
159
+ throw new AccessException ('Default values cannot be set from a lazy option or normalizer. ' );
159
160
}
160
161
161
162
// If an option is a closure that should be evaluated lazily, store it
@@ -248,7 +249,7 @@ public function hasDefault($option)
248
249
public function setRequired ($ optionNames )
249
250
{
250
251
if ($ this ->locked ) {
251
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
252
+ throw new AccessException ('Options cannot be made required from a lazy option or normalizer. ' );
252
253
}
253
254
254
255
foreach ((array ) $ optionNames as $ key => $ option ) {
@@ -329,7 +330,7 @@ public function getMissingOptions()
329
330
public function setDefined ($ optionNames )
330
331
{
331
332
if ($ this ->locked ) {
332
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
333
+ throw new AccessException ('Options cannot be defined from a lazy option or normalizer. ' );
333
334
}
334
335
335
336
foreach ((array ) $ optionNames as $ key => $ option ) {
@@ -397,12 +398,12 @@ public function getDefinedOptions()
397
398
public function setNormalizer ($ option , \Closure $ normalizer )
398
399
{
399
400
if ($ this ->locked ) {
400
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
401
+ throw new AccessException ('Normalizers cannot be set from a lazy option or normalizer. ' );
401
402
}
402
403
403
404
if (!isset ($ this ->defined [$ option ])) {
404
405
throw new UndefinedOptionsException (sprintf (
405
- 'The option "%s" does not exist. Known options are: "%s" ' ,
406
+ 'The option "%s" does not exist. Known options are: "%s". ' ,
406
407
$ option ,
407
408
implode ('", " ' , array_keys ($ this ->defined ))
408
409
));
@@ -452,7 +453,7 @@ public function setNormalizers(array $normalizers)
452
453
public function setAllowedValues ($ option , $ allowedValues = null )
453
454
{
454
455
if ($ this ->locked ) {
455
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
456
+ throw new AccessException ('Allowed values cannot be set from a lazy option or normalizer. ' );
456
457
}
457
458
458
459
// BC
@@ -466,7 +467,7 @@ public function setAllowedValues($option, $allowedValues = null)
466
467
467
468
if (!isset ($ this ->defined [$ option ])) {
468
469
throw new UndefinedOptionsException (sprintf (
469
- 'The option "%s" does not exist. Known options are: "%s" ' ,
470
+ 'The option "%s" does not exist. Known options are: "%s". ' ,
470
471
$ option ,
471
472
implode ('", " ' , array_keys ($ this ->defined ))
472
473
));
@@ -506,7 +507,7 @@ public function setAllowedValues($option, $allowedValues = null)
506
507
public function addAllowedValues ($ option , $ allowedValues = null )
507
508
{
508
509
if ($ this ->locked ) {
509
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
510
+ throw new AccessException ('Allowed values cannot be added from a lazy option or normalizer. ' );
510
511
}
511
512
512
513
// BC
@@ -520,7 +521,7 @@ public function addAllowedValues($option, $allowedValues = null)
520
521
521
522
if (!isset ($ this ->defined [$ option ])) {
522
523
throw new UndefinedOptionsException (sprintf (
523
- 'The option "%s" does not exist. Known options are: "%s" ' ,
524
+ 'The option "%s" does not exist. Known options are: "%s". ' ,
524
525
$ option ,
525
526
implode ('", " ' , array_keys ($ this ->defined ))
526
527
));
@@ -558,7 +559,7 @@ public function addAllowedValues($option, $allowedValues = null)
558
559
public function setAllowedTypes ($ option , $ allowedTypes = null )
559
560
{
560
561
if ($ this ->locked ) {
561
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
562
+ throw new AccessException ('Allowed types cannot be set from a lazy option or normalizer. ' );
562
563
}
563
564
564
565
// BC
@@ -572,7 +573,7 @@ public function setAllowedTypes($option, $allowedTypes = null)
572
573
573
574
if (!isset ($ this ->defined [$ option ])) {
574
575
throw new UndefinedOptionsException (sprintf (
575
- 'The option "%s" does not exist. Known options are: "%s" ' ,
576
+ 'The option "%s" does not exist. Known options are: "%s". ' ,
576
577
$ option ,
577
578
implode ('", " ' , array_keys ($ this ->defined ))
578
579
));
@@ -606,7 +607,7 @@ public function setAllowedTypes($option, $allowedTypes = null)
606
607
public function addAllowedTypes ($ option , $ allowedTypes = null )
607
608
{
608
609
if ($ this ->locked ) {
609
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
610
+ throw new AccessException ('Allowed types cannot be added from a lazy option or normalizer. ' );
610
611
}
611
612
612
613
// BC
@@ -620,7 +621,7 @@ public function addAllowedTypes($option, $allowedTypes = null)
620
621
621
622
if (!isset ($ this ->defined [$ option ])) {
622
623
throw new UndefinedOptionsException (sprintf (
623
- 'The option "%s" does not exist. Known options are: "%s" ' ,
624
+ 'The option "%s" does not exist. Known options are: "%s". ' ,
624
625
$ option ,
625
626
implode ('", " ' , array_keys ($ this ->defined ))
626
627
));
@@ -652,7 +653,7 @@ public function addAllowedTypes($option, $allowedTypes = null)
652
653
public function remove ($ optionNames )
653
654
{
654
655
if ($ this ->locked ) {
655
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
656
+ throw new AccessException ('Options cannot be removed from a lazy option or normalizer. ' );
656
657
}
657
658
658
659
foreach ((array ) $ optionNames as $ option ) {
@@ -679,7 +680,7 @@ public function remove($optionNames)
679
680
public function clear ()
680
681
{
681
682
if ($ this ->locked ) {
682
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
683
+ throw new AccessException ('Options cannot be cleared from a lazy option or normalizer. ' );
683
684
}
684
685
685
686
$ this ->defined = array ();
@@ -715,12 +716,13 @@ public function clear()
715
716
* @throws MissingOptionsException If a required option is missing
716
717
* @throws OptionDefinitionException If there is a cyclic dependency between
717
718
* lazy options and/or normalizers
719
+ * @throws NoSuchOptionException If a lazy option reads an unavailable option
718
720
* @throws AccessException If called from a lazy option or normalizer
719
721
*/
720
722
public function resolve (array $ options = array ())
721
723
{
722
724
if ($ this ->locked ) {
723
- throw new AccessException ('This method cannot be called from a lazy option or normalizer. ' );
725
+ throw new AccessException ('Options cannot be resolved from a lazy option or normalizer. ' );
724
726
}
725
727
726
728
// Allow this method to be called multiple times
@@ -734,7 +736,7 @@ public function resolve(array $options = array())
734
736
ksort ($ diff );
735
737
736
738
throw new UndefinedOptionsException (sprintf (
737
- (count ($ diff ) > 1 ? 'The options "%s" do not exist. ' : 'The option "%s" does not exist. ' ).' Known options are: "%s" ' ,
739
+ (count ($ diff ) > 1 ? 'The options "%s" do not exist. ' : 'The option "%s" does not exist. ' ).' Known options are: "%s". ' ,
738
740
implode ('", " ' , array_keys ($ diff )),
739
741
implode ('", " ' , array_keys ($ clone ->defined ))
740
742
));
@@ -779,8 +781,8 @@ public function resolve(array $options = array())
779
781
*
780
782
* @throws AccessException If accessing this method outside of
781
783
* {@link resolve()}
782
- * @throws \OutOfBoundsException If the option is not set
783
- * @throws InvalidOptionsException If an option doesn't fulfill the
784
+ * @throws NoSuchOptionException If the option is not set
785
+ * @throws InvalidOptionsException If the option doesn't fulfill the
784
786
* specified validation rules
785
787
* @throws OptionDefinitionException If there is a cyclic dependency between
786
788
* lazy options and/or normalizers
@@ -798,7 +800,18 @@ public function offsetGet($option)
798
800
799
801
// Check whether the option is set at all
800
802
if (!array_key_exists ($ option , $ this ->defaults )) {
801
- throw new \OutOfBoundsException (sprintf ('The option "%s" was not set. ' , $ option ));
803
+ if (!isset ($ this ->defined [$ option ])) {
804
+ throw new NoSuchOptionException (sprintf (
805
+ 'The option "%s" does not exist. Known options are: "%s". ' ,
806
+ $ option ,
807
+ implode ('", " ' , array_keys ($ this ->defined ))
808
+ ));
809
+ }
810
+
811
+ throw new NoSuchOptionException (sprintf (
812
+ 'The optional option "%s" has no value set. You should make sure it is set with "isset" before reading it. ' ,
813
+ $ option
814
+ ));
802
815
}
803
816
804
817
$ value = $ this ->defaults [$ option ];
0 commit comments