Add validation to directory key
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pcm\IconBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
@@ -18,12 +19,50 @@ class Configuration implements ConfigurationInterface
|
||||
->arrayNode('directories')
|
||||
->scalarPrototype()->end()
|
||||
->end()
|
||||
->arrayNode('palletes')
|
||||
->arrayNode('palletes') // Akshewally it is defined
|
||||
->variablePrototype()->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
$this->addValidationRules($treeBuilder->getRootNode());
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
private function addValidationRules(ArrayNodeDefinition $rootNode): void
|
||||
{
|
||||
$rootNode
|
||||
->children()
|
||||
->arrayNode('directories')
|
||||
->validate()
|
||||
->ifEmpty()
|
||||
->thenInvalid("Directories cannot be empty!")
|
||||
->end()
|
||||
->scalarPrototype()
|
||||
->validate()
|
||||
->ifTrue(fn($path) => !is_dir($path))
|
||||
->thenInvalid('%s is not a directory!')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
// $rootNode
|
||||
// ->children()
|
||||
// ->arrayNode('directories')
|
||||
// ->scalarPrototype()
|
||||
// ->validate()
|
||||
// ->ifTrue(function ($value) {
|
||||
// // Add validation logic for directories here
|
||||
// return false;
|
||||
// })
|
||||
|
||||
// ->thenInvalid('Invalid directory')
|
||||
// ->end()
|
||||
// ->end()
|
||||
// ->end()
|
||||
// ->end()
|
||||
// ;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user