Exemplo n.º 1
0
 /**
  * Tests the convertToArray method.
  */
 public function testConvertToArray()
 {
     // simple case
     $optionCategory = new OptionCategory();
     $mainCategory = new OptionCategory('twomartens.core');
     $options = [new Option(0, 'one', 'string', 'hello'), new Option(0, 'two', 'boolean', false), new Option(0, 'three', 'array', [1, 2, 3])];
     $mainCategory->setOptions($options);
     $optionCategory->setCategories([$mainCategory]);
     $yamlData = ConfigUtil::convertToArray($optionCategory);
     $expectedYamlData = ['twomartens.core' => ['one' => 'hello', 'two' => false, 'three' => [1, 2, 3]]];
     $this->assertEquals($expectedYamlData, $yamlData);
     // complex case
     $optionCategory = new OptionCategory();
     $acpCategory = new OptionCategory('acp');
     $ourCategory = new OptionCategory('twomartens.core');
     $acpCategory->setCategories([$ourCategory]);
     $optionCategory->setCategories([$acpCategory]);
     $options = [new Option(0, 'one', 'boolean', true), new Option(0, 'two', 'string', 'foo'), new Option(0, 'three', 'array', [4, 5, 6])];
     $ourCategory->setOptions($options);
     $yamlData = ConfigUtil::convertToArray($optionCategory);
     $expectedYamlData = ['acp' => ['twomartens.core' => ['one' => true, 'two' => 'foo', 'three' => [4, 5, 6]]]];
     $this->assertEquals($expectedYamlData, $yamlData);
 }
Exemplo n.º 2
0
 /**
  * Writes the config files.
  *
  * ATTENTION: This method DOES NOT perform any sanitize actions. It
  * overwrites the config files with the options entirely.
  */
 private function writeConfig()
 {
     // updates existing files and adds new files if necessary
     $path = null;
     $roleNames = array_keys($this->optionData);
     $baseNames = [];
     foreach ($this->finder as $file) {
         /** @var SplFileInfo $file */
         if ($path === null) {
             $path = $file->getPath();
             break;
         }
     }
     foreach ($roleNames as $roleName) {
         $baseNames[] = strtolower($roleName);
     }
     foreach ($baseNames as $basename) {
         $category = $this->optionData[strtoupper($basename)];
         $yaml = ConfigUtil::convertToArray($category);
         $dumpReady = $this->dumper->dump($yaml, 3);
         $writePath = $path . '/' . $basename . '.yml';
         $this->filesystem->dumpFile($writePath, $dumpReady);
     }
     foreach ($this->toBeRemoved as $toRemove) {
         $basename = strtolower($toRemove) . '.yml';
         $deletePath = $path . '/' . $basename;
         $this->filesystem->remove($deletePath);
     }
     $this->toBeRemoved = [];
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function setOptions(OptionCategory $options)
 {
     $this->optionsYAML = ConfigUtil::convertToArray($options);
 }