16 private $declarations;
22 $this->configSchema = $configSchema;
34 $alreadyComputed = [];
36 foreach ( $this->declarations as $key => $unused ) {
37 $this->computeDefaultFor( $key, $configBuilder, $alreadyComputed );
51 private function computeDefaultFor(
53 ConfigBuilder $configBuilder,
54 array &$alreadyComputed = [],
55 array $currentlyComputing = []
57 if ( !isset( $this->declarations[ $key ] ) || isset( $alreadyComputed[ $key ] ) ) {
60 if ( isset( $currentlyComputing[ $key ] ) ) {
61 throw new LogicException(
62 'Cyclic dependency when computing dynamic default: ' .
63 implode(
' -> ', array_keys( $currentlyComputing ) ) .
" -> $key"
67 $configBuilder->
get( $key ) !==
68 $this->configSchema->getDefaultFor( $key )
71 $alreadyComputed[ $key ] =
true;
76 $currentlyComputing[ $key ] =
true;
78 $callback = $this->declarations[ $key ][
'callback'];
79 $argNames = $this->declarations[ $key ][
'use'] ?? [];
82 foreach ( $argNames as $argName ) {
83 $this->computeDefaultFor(
89 $args[] = $configBuilder->
get( $argName );
92 $configBuilder->
set( $key, $callback( ...$args ) );
94 $alreadyComputed[ $key ] =
true;