composer-config-plugin
composer-config-plugin copied to clipboard
Config validation
Would be nice to have an ability to check all config before error will be caught in runtime. I think we can implement it with console command (or add after rebuild process) with usage http://github.com/yiisoft/validator.
Action plan:
- [ ] Decide about format
- [ ] Implement feature
- [ ] Make documentation
- [ ] Cover all yii-* packages configs
Welcome to discussion.
https://github.com/yiisoft/composer-config-plugin#known-issues
I've imagined something like this: every package can define own config validators:
"extra": {
"config-plugin": {
"params": "config/params.php",
"common": "config/common.php"
},
"config-plugin-validators": {
"SomePackage\\MyConfigValidator": {
"configNames": ["common", "web"],
"otherOption": "value"
},
},
},
use Yiisoft\Composer\Config\Config\ValidatorInterface;
class MyConfigValidator implements ValidatorInterface
{
public function __construct(array $options);
public function isApplicable($configName): boolean
{
return in_array($configName, $this->configNames, true);
}
public function validate($configName, $configArray): void
{
if (empty($configArray['importantOption'])) {
throw Exception('importantOption must be set');
}
}
}
Not sure about configNames. Just first thoughts...
I think after switching to .php configs it could be like this:
return [
'configs' => [
'params' => [
'params.php',
[
'name' => 'params-local.php',
'validator' => ParamsLocalValidator::class,
],
// or
'params-local.php' => [
'validator' => ParamsLocalValidator::class,
],
]
]
]
So json format can be similar