16 private $declarations;
19 $this->configSchema = $configSchema;
31 $alreadyComputed = [];
33 foreach ( $this->declarations as $key => $unused ) {
34 $this->computeDefaultFor( $key, $configBuilder, $alreadyComputed );
48 private function computeDefaultFor(
50 ConfigBuilder $configBuilder,
51 array &$alreadyComputed = [],
52 array $currentlyComputing = []
54 if ( !isset( $this->declarations[ $key ] ) || isset( $alreadyComputed[ $key ] ) ) {
57 if ( isset( $currentlyComputing[ $key ] ) ) {
58 throw new LogicException(
59 'Cyclic dependency when computing dynamic default: ' .
60 implode(
' -> ', array_keys( $currentlyComputing ) ) .
" -> $key"
64 $configBuilder->
get( $key ) !==
65 $this->configSchema->getDefaultFor( $key )
68 $alreadyComputed[ $key ] =
true;
73 $currentlyComputing[ $key ] =
true;
75 $callback = $this->declarations[ $key ][
'callback'];
76 $argNames = $this->declarations[ $key ][
'use'] ?? [];
79 foreach ( $argNames as $argName ) {
80 $this->computeDefaultFor(
86 $args[] = $configBuilder->
get( $argName );
89 $configBuilder->
set( $key, $callback( ...$args ) );
91 $alreadyComputed[ $key ] =
true;