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
// Yet undefined options can be marked as resolved, because we only need
181
214
// to resolve options with lazy closures, normalizers or validation
@@ -354,6 +387,11 @@ public function getDefinedOptions()
354
387
returnarray_keys($this->defined);
355
388
}
356
389
390
+
publicfunctionisNested(string$option): bool
391
+
{
392
+
returnisset($this->nested[$option]);
393
+
}
394
+
357
395
/**
358
396
* Deprecates an option, allowed types or values.
359
397
*
@@ -671,6 +709,7 @@ public function clear()
671
709
672
710
$this->defined = array();
673
711
$this->defaults = array();
712
+
$this->nested = array();
674
713
$this->required = array();
675
714
$this->resolved = array();
676
715
$this->lazy = array();
@@ -803,6 +842,32 @@ public function offsetGet($option)
803
842
804
843
$value = $this->defaults[$option];
805
844
845
+
// Resolve the option if it is a nested definition
846
+
if (isset($this->nested[$option])) {
847
+
// If the closure is already being called, we have a cyclic dependency
848
+
if (isset($this->calling[$option])) {
849
+
thrownewOptionDefinitionException(sprintf('The options "%s" have a cyclic dependency.', implode('", "', array_keys($this->calling))));
850
+
}
851
+
852
+
if (!\is_array($value)) {
853
+
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, 'array')));
854
+
}
855
+
856
+
// The following section must be protected from cyclic calls.
857
+
// BEGIN
858
+
$this->calling[$option] = true;
859
+
try {
860
+
$resolver = newself();
861
+
foreach ($this->nested[$option] as$closure) {
862
+
$closure($resolver, $this);
863
+
}
864
+
$value = $resolver->resolve($value);
865
+
} finally {
866
+
unset($this->calling[$option]);
867
+
}
868
+
// END
869
+
}
870
+
806
871
// Resolve the option if the default value is lazily evaluated
807
872
if (isset($this->lazy[$option])) {
808
873
// If the closure is already being called, we have a cyclic
0 commit comments