Skip to content
Permalink
Browse files

introduced new Nette\DI\InvalidConfigurationException

  • Loading branch information...
dg committed Mar 12, 2019
1 parent adf9c5d commit 368865fabe17b3bfaba88c7950852f88817da2f9
@@ -228,7 +228,7 @@ public function processExtensions(): void
} elseif ($extra = key(array_diff_key($config, $this->extensions))) {
$hint = Nette\Utils\ObjectHelpers::getSuggestion(array_keys(self::RESERVED + $this->extensions), $extra);
throw new Nette\InvalidStateException(
throw new InvalidConfigurationException(
"Found section '$extra' in configuration, but corresponding extension is missing"
. ($hint ? ", did you mean '$hint'?" : '.')
);
@@ -72,7 +72,7 @@ public function validateConfig(array $expected, array $config = null, string $na
$name = $name ? str_replace('.', ' › ', $name) : $this->name;
$hint = Nette\Utils\ObjectHelpers::getSuggestion(array_keys($expected), key($extra));
$extra = $hint ? key($extra) : implode("', '{$name} › ", array_keys($extra));
throw new Nette\InvalidStateException("Unknown configuration option '{$name} › {$extra}'" . ($hint ? ", did you mean '{$name} › {$hint}'?" : '.'));
throw new Nette\DI\InvalidConfigurationException("Unknown configuration option '{$name} › {$extra}'" . ($hint ? ", did you mean '{$name} › {$hint}'?" : '.'));
}
return Config\Helpers::merge($config, $expected);
}
@@ -44,7 +44,7 @@ public function process(array $arr): array
foreach ($arr as $key => $val) {
if (is_string($key) && substr($key, -1) === self::PREVENT_MERGING_SUFFIX) {
if (!is_array($val) && $val !== null) {
throw new Nette\InvalidStateException("Replacing operator is available only for arrays, item '$key' is not array.");
throw new Nette\DI\InvalidConfigurationException("Replacing operator is available only for arrays, item '$key' is not array.");
}
$key = substr($key, 0, -1);
$val[Helpers::PREVENT_MERGING] = true;
@@ -13,7 +13,6 @@
use Nette\DI\Definitions;
use Nette\DI\Definitions\Statement;
use Nette\DI\Extensions;
use Nette\DI\ServiceCreationException;
use Nette\Utils\Validators;
@@ -138,7 +137,7 @@ public function normalizeConfig($config): array
foreach (['class' => 'type', 'dynamic' => 'imported'] as $alias => $original) {
if (array_key_exists($alias, $config)) {
if (array_key_exists($original, $config)) {
throw new Nette\InvalidStateException("Options '$alias' and '$original' are aliases, use only '$original'.");
throw new Nette\DI\InvalidConfigurationException("Options '$alias' and '$original' are aliases, use only '$original'.");
}
$config[$original] = $config[$alias];
unset($config[$alias]);
@@ -147,7 +146,7 @@ public function normalizeConfig($config): array
return $config;
} else {
throw new Nette\InvalidStateException('Unexpected format of service definition');
throw new Nette\DI\InvalidConfigurationException('Unexpected format of service definition');
}
}
@@ -173,7 +172,7 @@ private function loadDefinition(?string $name, array $config): void
$this->builder->removeDefinition($name);
return;
} elseif (!empty($config['alteration']) && !$this->builder->hasDefinition($name)) {
throw new ServiceCreationException('missing original definition for alteration.');
throw new Nette\DI\InvalidConfigurationException('missing original definition for alteration.');
}
unset($config['alteration']);
@@ -184,7 +183,7 @@ private function loadDefinition(?string $name, array $config): void
$this->{$scheme['method']}($def, $config, $name);
$this->updateDefinition($def, $config);
} catch (\Exception $e) {
throw new ServiceCreationException(($name ? "Service '$name': " : '') . $e->getMessage(), 0, $e);
throw new Nette\DI\InvalidConfigurationException(($name ? "Service '$name': " : '') . $e->getMessage(), 0, $e);
}
}
@@ -356,7 +355,7 @@ private function validateFields(array $config, array $fields): void
return Nette\Utils\ObjectHelpers::getSuggestion($expected, $error);
}, $error));
$hint = $hints ? ", did you mean '" . implode("', '", $hints) . "'?" : '.';
throw new Nette\InvalidStateException(sprintf("Unknown key '%s' in definition of service$hint", implode("', '", $error)));
throw new Nette\DI\InvalidConfigurationException(sprintf("Unknown key '%s' in definition of service$hint", implode("', '", $error)));
}
foreach ($fields as $field => $expected) {
@@ -59,7 +59,7 @@ public function loadConfiguration()
$in = $batch['in'];
if (!is_string($in) || !is_dir($in)) {
throw new Nette\InvalidStateException("Option '{$this->name} › {$name} › in' must be valid directory name, " . (is_string($in) ? "'$in'" : gettype($in)) . ' given.');
throw new Nette\DI\InvalidConfigurationException("Option '{$this->name} › {$name} › in' must be valid directory name, " . (is_string($in) ? "'$in'" : gettype($in)) . ' given.');
}
foreach ($this->findClasses($batch) as $class) {
@@ -39,3 +39,11 @@ public function setMessage(string $message): self
class NotAllowedDuringResolvingException extends Nette\InvalidStateException
{
}
/**
* Error in configuration.
*/
class InvalidConfigurationException extends Nette\InvalidStateException
{
}
@@ -59,4 +59,4 @@ $compiler->addConfig([
Assert::exception(function () use ($compiler, $class) {
$compiler->setClassName($class)
->compile();
}, DI\ServiceCreationException::class, "Service 's3': missing original definition for alteration.");
}, DI\InvalidConfigurationException::class, "Service 's3': missing original definition for alteration.");
@@ -21,4 +21,4 @@ services:
bad:
alteration: yes
');
}, Nette\DI\ServiceCreationException::class, "Service 'bad': missing original definition for alteration.");
}, Nette\DI\InvalidConfigurationException::class, "Service 'bad': missing original definition for alteration.");
@@ -22,4 +22,4 @@ Assert::throws(function () {
setups: []
foo: bar
');
}, Nette\InvalidStateException::class, "Unknown key 'autowire', 'setups', 'foo' in definition of service, did you mean 'autowired', 'setup'?");
}, Nette\DI\InvalidConfigurationException::class, "Unknown key 'autowire', 'setups', 'foo' in definition of service, did you mean 'autowired', 'setup'?");
@@ -48,20 +48,20 @@ test(function () {
Assert::exception(function () {
$ext = new MyExtension;
$ext->validateConfig(['a' => 1, 'b' => 1], ['c' => 1]);
}, Nette\InvalidStateException::class, "Unknown configuration option 'my › c', did you mean 'my › a'?");
}, Nette\DI\InvalidConfigurationException::class, "Unknown configuration option 'my › c', did you mean 'my › a'?");
Assert::exception(function () {
$ext = new MyExtension;
$ext->validateConfig(['a' => 1, 'b' => 1], ['ccc' => 1, 'ddd' => 2]);
}, Nette\InvalidStateException::class, "Unknown configuration option 'my › ccc', 'my › ddd'.");
}, Nette\DI\InvalidConfigurationException::class, "Unknown configuration option 'my › ccc', 'my › ddd'.");
Assert::exception(function () {
$ext = new MyExtension;
$ext->validateConfig(['a' => 1, 'b' => 1], ['c' => 1, 'd' => 1], 'name.x');
}, Nette\InvalidStateException::class, "Unknown configuration option 'name › x › c', did you mean 'name › x › a'?");
}, Nette\DI\InvalidConfigurationException::class, "Unknown configuration option 'name › x › c', did you mean 'name › x › a'?");
Assert::exception(function () {
$ext = new MyExtension;
$ext->setConfig(['c' => 1, 'd' => 1]);
$ext->validateConfig(['a' => 1, 'b' => 1]);
}, Nette\InvalidStateException::class, "Unknown configuration option 'my › c', did you mean 'my › a'?");
}, Nette\DI\InvalidConfigurationException::class, "Unknown configuration option 'my › c', did you mean 'my › a'?");
@@ -48,4 +48,4 @@ Assert::same(['imported' => 'val'], $processor->normalizeConfig(['dynamic' => 'v
Assert::exception(function () use ($processor) {
$processor->normalizeConfig(['class' => 'val', 'type' => 'val']);
}, Nette\InvalidStateException::class, "Options 'class' and 'type' are aliases, use only 'type'.");
}, Nette\DI\InvalidConfigurationException::class, "Options 'class' and 'type' are aliases, use only 'type'.");
@@ -37,8 +37,8 @@ Assert::same(['item' => []], merge('item!: []', 'item: []'));
Assert::exception(function () {
merge('item!: 231', 'item:');
}, Nette\InvalidStateException::class);
}, Nette\DI\InvalidConfigurationException::class);
Assert::exception(function () {
merge('item!: 231', 'item: 231');
}, Nette\InvalidStateException::class);
}, Nette\DI\InvalidConfigurationException::class);
@@ -12,7 +12,7 @@ Assert::exception(function () {
search:
in: invalid
');
}, Nette\InvalidStateException::class, "Option 'search › default › in' must be valid directory name, 'invalid' given.");
}, Nette\DI\InvalidConfigurationException::class, "Option 'search › default › in' must be valid directory name, 'invalid' given.");
Assert::exception(function () {
@@ -21,4 +21,4 @@ Assert::exception(function () {
batch:
in: []
');
}, Nette\InvalidStateException::class, "Option 'search › batch › in' must be valid directory name, array given.");
}, Nette\DI\InvalidConfigurationException::class, "Option 'search › batch › in' must be valid directory name, array given.");

0 comments on commit 368865f

Please sign in to comment.
You can’t perform that action at this time.