public function __construct(array $files = null) { $files = is_null($files) ? $this->findAllConfigurationFiles() : $files; if (count($files) == 0) { throw new \StackFormation\Exception\NoBlueprintsFoundException("Could not find any blueprints.yml configuration files"); } $yamlParser = new \Symfony\Component\Yaml\Parser(); $config = []; $stacknames = []; foreach ($files as $file) { $basePath = dirname(realpath($file)); $tmp = $yamlParser->parse(file_get_contents($file)); if (isset($tmp['blueprints']) && is_array($tmp['blueprints'])) { foreach ($tmp['blueprints'] as &$blueprintConfig) { // check for multiple usage of the same stackname $stackname = $blueprintConfig['stackname']; if (in_array($stackname, $stacknames)) { throw new \Exception("Stackname '{$stackname}' was declared more than once."); } if (empty($blueprintConfig['template'])) { throw new \Exception("Stackname '{$stackname}' does not specify a template."); } $stacknames[] = $stackname; $blueprintConfig['basepath'] = $basePath; } } $config[] = $tmp; } $processor = new \Symfony\Component\Config\Definition\Processor(); $this->conf = $processor->processConfiguration(new ConfigTreeBuilder(), $config); }
/** * @param array $config */ function process(array $config) { $treeBuilder = new \Symfony\Component\Config\Definition\Builder\TreeBuilder(); $rootNode = $treeBuilder->root('root', 'array'); $root = $rootNode->children(); $mail = $root->arrayNode('mail')->canBeEnabled()->addDefaultsIfNotSet()->children(); $mail->scalarNode('to')->cannotBeEmpty()->isRequired()->end(); $mail->scalarNode('subject')->cannotBeEmpty()->isRequired()->end(); $mail->scalarNode('from')->cannotBeEmpty()->isRequired()->end(); $processor = new \Symfony\Component\Config\Definition\Processor(); return $processor->process($treeBuilder->buildTree(), ['root' => $config]); }