addValidationRules($treeBuilder->getRootNode()); return $treeBuilder; } private function addValidationRules(ArrayNodeDefinition $rootNode): void { // I've split the tree up like this because Intelephense was crying. // Plus I think it's a little easier to read. $rootNode ->children() ->arrayNode('default') ->addDefaultsIfNotSet() ->children() ->scalarNode('colour')->defaultValue(self::DEFAULT_COLOUR)->end() ->integerNode('size')->defaultValue(self::DEFAULT_SIZE)->end() ->end() ->end() ->end() ; $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('colours') ->validate() ->ifEmpty() ->thenInvalid('Colours cannot be empty!') ->end() ->arrayPrototype() ->normalizeKeys(false) # Don't normalize hyphens into underscores etc ->children() ->scalarNode('fill')->isRequired()->end() ->scalarNode('stroke')->isRequired()->end() ->scalarNode('fill-hover')->isRequired()->end() ->scalarNode('stroke-hover')->isRequired()->end() ->scalarNode('fill-group-hover')->isRequired()->end() ->scalarNode('stroke-group-hover')->isRequired()->end() ->end() ->end() ->end() ->end() ; } }