Skip to content

Instantly share code, notes, and snippets.

@loalf
Created November 29, 2012 14:49
Show Gist options
  • Save loalf/4169549 to your computer and use it in GitHub Desktop.
Save loalf/4169549 to your computer and use it in GitHub Desktop.
Validacion en el componente Config
/**
* Configuracion en archivo config.yml
*
* mi_bundle:
* config_file: "path/to/file.ini"
*
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('mi_bundle');
$default = "/default/path/to/file.ini";
$rootNode
->children()
->scalarNode("config_file")
->defaultValue($default)
->validate()
->ifTrue(function($v){ return !file_exists($v); })
->thenInvalid("The config file %s doesn't exist")
->end()
->end()
->end();
return $treeBuilder;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment