/** * Extracts paths of all sections in the given configuration tree * * @param array $result * @param SectionDefinition $tree * @param string $parentPath */ protected function extractSectionPaths(array &$result, SectionDefinition $tree, $parentPath) { $subSections = $tree->getSubSections(); foreach ($subSections as $subSection) { $path = empty($parentPath) ? $subSection->getName() : $parentPath . '/' . $subSection->getName(); $result[] = $path; $this->extractSectionPaths($result, $subSection, $path); } }
/** * @return array */ public function getApiTreeProvider() { $root = new SectionDefinition(''); $section1 = new SectionDefinition('section1'); $root->addSubSection($section1); $section1->addVariable(new VariableDefinition('some_field', 'string')); $section1->addVariable(new VariableDefinition('some_api_only_field', 'integer')); $section11 = new SectionDefinition('section11'); $section1->addSubSection($section11); $section11->addVariable(new VariableDefinition('some_another_field', 'string')); return ['root section' => [null, $root], 'top section' => ['section1', $section1], 'sub section' => ['section1/section11', $section11]]; }
public function testGetData() { $path = 'section1/section11'; $apiTree = new SectionDefinition('section11'); $apiTree->addVariable(new VariableDefinition('acme.item1', 'string')); $subSection1 = new SectionDefinition('sub_section1'); $apiTree->addSubSection($subSection1); $subSection1->addVariable(new VariableDefinition('acme.item2', 'integer')); $subSection11 = new SectionDefinition('sub_section11'); $subSection1->addSubSection($subSection11); $subSection11->addVariable(new VariableDefinition('acme.item2', 'integer')); $subSection11->addVariable(new VariableDefinition('acme.item3', 'array')); $this->configProvider->expects($this->once())->method('getApiTree')->with($path)->will($this->returnValue($apiTree)); $this->configManager->expects($this->any())->method('get')->will($this->returnValueMap([['acme.item1', false, false, 'val1'], ['acme.item2', false, false, 123], ['acme.item3', false, false, ['val1' => 1, 'val2' => true]]])); $datetime = new \DateTime('now', new \DateTimeZone('UTC')); $this->configManager->expects($this->any())->method('getInfo')->will($this->returnValue(['createdAt' => $datetime, 'updatedAt' => $datetime])); $this->assertSame([['key' => 'acme.item1', 'type' => 'string', 'value' => 'val1', 'createdAt' => $datetime, 'updatedAt' => $datetime], ['key' => 'acme.item2', 'type' => 'integer', 'value' => 123, 'createdAt' => $datetime, 'updatedAt' => $datetime], ['key' => 'acme.item3', 'type' => 'array', 'value' => ['val1' => 1, 'val2' => true], 'createdAt' => $datetime, 'updatedAt' => $datetime]], $this->manager->getData($path)); }
/** * @param string $sectionName * @param array $tree * * @return SectionDefinition */ protected function buildApiTree($sectionName, array $tree) { $section = new SectionDefinition($sectionName); foreach ($tree as $key => $val) { if ($key === 'section') { continue; } if (!empty($val['section'])) { $section->addSubSection($this->buildApiTree($key, $val)); } else { $section->addVariable(new VariableDefinition($key, $val['type'])); } } return $section; }