14 private $configSchema;
19 private $declarations;
25 $this->configSchema = $configSchema;
37 $alreadyComputed = [];
39 foreach ( $this->declarations as $key => $unused ) {
40 $this->computeDefaultFor( $key, $configBuilder, $alreadyComputed );
54 private function computeDefaultFor(
56 ConfigBuilder $configBuilder,
57 array &$alreadyComputed = [],
58 array $currentlyComputing = []
60 if ( !isset( $this->declarations[ $key ] ) || isset( $alreadyComputed[ $key ] ) ) {
63 if ( isset( $currentlyComputing[ $key ] ) ) {
64 throw new LogicException(
65 'Cyclic dependency when computing dynamic default: ' .
66 implode(
' -> ', array_keys( $currentlyComputing ) ) .
" -> $key"
70 $configBuilder->
get( $key ) !==
71 $this->configSchema->getDefaultFor( $key )
74 $alreadyComputed[ $key ] =
true;
79 $currentlyComputing[ $key ] =
true;
81 $callback = $this->declarations[ $key ][
'callback'];
82 $argNames = $this->declarations[ $key ][
'use'] ?? [];
85 foreach ( $argNames as $argName ) {
86 $this->computeDefaultFor(
92 $args[] = $configBuilder->
get( $argName );
95 $configBuilder->
set( $key, $callback( ...
$args ) );
97 $alreadyComputed[ $key ] =
true;