6 use InvalidArgumentException;
7 use Wikimedia\Assert\Assert;
29 private $options = [];
42 foreach (
$keys as $key ) {
43 foreach ( $sources as
$source ) {
46 $this->options[$key] =
$source->get( $key );
50 if ( array_key_exists( $key,
$source->options ) ) {
51 $this->options[$key] =
$source->get( $key );
55 if ( array_key_exists( $key,
$source ) ) {
56 $this->options[$key] =
$source[$key];
61 throw new InvalidArgumentException(
"Key \"$key\" not found in input sources" );
72 if ( $this->keys !== $expectedKeys ) {
73 $extraKeys = array_diff( $this->keys, $expectedKeys );
74 $missingKeys = array_diff( $expectedKeys, $this->keys );
75 Assert::precondition( !$extraKeys && !$missingKeys,
78 ?
'Unsupported options passed: ' . implode(
', ', $extraKeys ) .
'!'
80 ) . ( $extraKeys && $missingKeys ?
' ' :
'' ) . (
82 ?
'Required options missing: ' . implode(
', ', $missingKeys ) .
'!'
93 public function get( $key ) {
94 if ( !array_key_exists( $key, $this->options ) ) {
95 throw new InvalidArgumentException(
"Unrecognized option \"$key\"" );
97 return $this->options[$key];
Interface for configuration instances.