/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->getHelper('config')->getConfiguration(); $loader = new YamlLoader(); $array = $loader->loadFromFile(__DIR__ . '/../../resources/schema.yml'); $schema = new MetaYaml($array); $schema->validate($config); $output->writeln('<info>Configuration is valid</info>'); }
public function testDocumentationRoot() { $this->if($yaml_loader = new YamlLoader())->and($schema = $yaml_loader->loadFromFile('test/data/TestTypes/Schema.yml'))->and($object = new testedClass($schema, true))->then->object($object)->isInstanceOf('RomaricDrigon\\MetaYaml\\MetaYaml')->array($object->getDocumentationForNode(array('texte')))->isEqualTo(array('name' => 'texte', 'node' => array('_type' => 'text'), 'prefix' => '_'))->array($object->getDocumentationForNode(array('paragraph')))->isEqualTo(array('name' => 'paragraph', 'node' => array('_type' => 'array', '_children' => array('line_1' => array('_type' => 'text'), 'line_2' => array('_type' => 'text'))), 'prefix' => '_'))->array($object->getDocumentationForNode(array('paragraph', 'line_1')))->isEqualTo(array('name' => 'line_1', 'node' => array('_type' => 'text'), 'prefix' => '_'))->array($object->getDocumentationForNode(array('prototype_bool', '1')))->isEqualTo(array('name' => '1', 'node' => array('_type' => 'boolean'), 'prefix' => '_'))->array($object->getDocumentationForNode(array('test_choice')))->isEqualTo(array('name' => 'test_choice', 'node' => array('_type' => 'choice', '_choices' => array(1 => array('_type' => 'enum', '_values' => array('windows', 'linux')), 2 => array('_type' => 'number'), 3 => array('_type' => 'array', '_children' => array('one_item' => array('_type' => 'number'), 'another_item' => array('_type' => 'text'))))), 'prefix' => '_'))->array($object->getDocumentationForNode(array('test_choice', 'one_item')))->isEqualTo(array('name' => 'one_item', 'node' => array(3 => array('_type' => 'number'), '_is_choice' => 'true'), 'prefix' => '_'))->array($object->getDocumentationForNode(array('choice_of_partial')))->isEqualTo(array('name' => 'choice_of_partial', 'node' => array('_type' => 'choice', '_choices' => array(1 => array('_type' => 'text'), 2 => array('_type' => 'text'))), 'prefix' => '_'))->array($object->getDocumentationForNode(array('array_of_partial')))->isEqualTo(array('name' => 'array_of_partial', 'node' => array('_type' => 'array', '_children' => array(1 => array('_type' => 'text'), 2 => array('_type' => 'text'))), 'prefix' => '_'))->array($object->getDocumentationForNode(array('prototype_partial')))->isEqualTo(array('name' => 'prototype_partial', 'node' => array('_type' => 'prototype', '_prototype' => array('_type' => 'text')), 'prefix' => '_'))->array($object->getDocumentationForNode(array('choice_of_choice', 'a')))->isEqualTo(array('name' => 'a', 'node' => array('_is_choice' => 'true', 0 => array('_type' => 'choice', '_choices' => array(10 => array('_type' => 'array', '_children' => array('b' => array('_type' => 'text')))))), 'prefix' => '_'))->array($object->getDocumentationForNode(array('choice_of_choice', 'a', 'b')))->isEqualTo(array('name' => 'b', 'node' => array(0 => array(10 => array('_type' => 'text'), '_is_choice' => 'true'), '_is_choice' => 'true'), 'prefix' => '_'))->array($object->getDocumentationForNode(array('deep_partial'), true))->isEqualTo(array('name' => 'deep_partial', 'node' => array('_type' => 'array', '_children' => array('a' => array('_type' => 'choice', '_choices' => array(0 => array('_type' => 'text'))), 'b' => array('_type' => 'array', '_children' => array('block' => array('_type' => 'array', '_children' => array('line_1' => array('_type' => 'text'), 'line_2' => array('_type' => 'text'))), 'line' => array('_type' => 'text'), 'protoline' => array('_type' => 'prototype', '_prototype' => array('_type' => 'text')))))), 'prefix' => '_'))->exception(function () use($object) { $object->getDocumentationForNode(array('paragraph', 'unknown')); })->hasMessage('Unable to find child unknown')->exception(function () use($object) { $object->getDocumentationForNode(array('wrong_partial')); })->hasMessage("You're using a partial but partial 'unknown' is not defined in your schema")->exception(function () use($object) { $object->getDocumentationForNode(array('loop_partial'), true); })->hasMessage('Partial loop detected while using unfold_partial option'); }
/** * {@inheritdoc} */ public function validate(array $data) { $loader = new YamlLoader(); $schemaContent = $loader->loadFromFile(__DIR__ . '/../definitionSchema.yml'); $schema = new MetaYaml($schemaContent); try { $schema->validate($data); } catch (\Exception $e) { throw new \LogicException($e->getMessage(), $e->getCode(), $e); } }
public static function setupConfig(Application $app) { $loader = new YamlLoader(); $schema = new MetaYaml($loader->loadFromFile(__DIR__ . '/config_schema.yml')); $schema->validate($config = $loader->loadFromFile(__DIR__ . '/../config/config.yml')); foreach ($config as $key => $value) { $app->setConfig($key, $value); } if (array_key_exists('SCRIPT_NAME', $_SERVER) && is_string($_SERVER['SCRIPT_NAME']) && !empty($_SERVER['SCRIPT_NAME'])) { $dir = dirname($_SERVER['SCRIPT_NAME']); } else { $dir = '/'; } $app->setConfig('dir', $dir); }
public function testBase() { $this->if($object = new testedClass())->then->object($object)->isInstanceOf('RomaricDrigon\\MetaYaml\\Loader\\YamlLoader')->array($object->loadFromFile('test/data/TestBasic/TestBase.yml'))->isEqualTo(array('fleurs' => array('rose' => 'une rose', 'violette' => 'une violette'))); }
<?php /* * This file is part of the Supervisor Monitor project. * * (c) Márk Sági-Kazár <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use RomaricDrigon\MetaYaml\Loader\YamlLoader; use RomaricDrigon\MetaYaml\MetaYaml; use Supervisor\Monitor\Manager; return ['di' => ['manager' => ['definition' => function () { $loader = new YamlLoader(); $schema = new MetaYaml($loader->loadFromFile(__DIR__ . '/schema.yml')); $schema->validate($config = $loader->loadFromFile(__DIR__ . '/../config/supervisor.yml')); return new Manager($config); }], 'twig_loader' => ['class' => 'Twig_Loader_Filesystem', 'arguments' => [__DIR__ . '/views']], 'twig_extension' => ['class' => 'Supervisor\\Monitor\\TwigExtension'], 'twig' => ['class' => 'Twig_Environment', 'arguments' => ['twig_loader'], 'methods' => ['addExtension' => ['twig_extension']]], 'controller' => ['class' => 'Supervisor\\Monitor\\Controller', 'arguments' => ['app']]]];
public function testAdvancedBase() { $this->if($loader = new YamlLoader())->and($data = $loader->loadFromFile('test/data/TestAdvanced/TestBase.yml'))->and($config = $loader->loadFromFile('test/data/TestAdvanced/Schema.yml'))->and($object = new testedClass())->then->boolean($object->validate($config, $data))->isEqualTo(true); }