コード例 #1
0
ファイル: SectionTest.php プロジェクト: kss-php/kss-php
 /**
  * @test
  */
 public function calcDepthWords()
 {
     $this->assertEquals(0, Section::calcDepth('Forms'));
     $this->assertEquals(0, Section::calcDepth('Forms.'));
     $this->assertEquals(0, Section::calcDepth('Forms -'));
     $this->assertEquals(1, Section::calcDepth('Forms.Buttons'));
     $this->assertEquals(1, Section::calcDepth('Forms - Buttons'));
     $this->assertEquals(2, Section::calcDepth('Forms.Buttons.Actions'));
     $this->assertEquals(2, Section::calcDepth('Forms - Buttons - Special Actions'));
 }
コード例 #2
0
ファイル: Parser.php プロジェクト: kss-php/kss-php
 /**
  * Returns an array of children for a specified section reference
  *
  * @param string $reference
  * @param int $levelsDown OPTIONAL
  *
  * @return array
  */
 public function getSectionChildren($reference, $levelsDown = null)
 {
     $reference = strtolower(Section::normalizeReference($reference));
     $this->sortSections();
     $sectionKeys = array_keys($this->sections);
     $sections = array();
     $maxDepth = null;
     if ($levelsDown !== null) {
         $maxDepth = Section::calcDepth($reference) + $levelsDown;
     }
     $reference = Section::trimReference($reference);
     $reference .= '.';
     foreach ($sectionKeys as $sectionKey) {
         $testSectionKey = strtolower(Section::normalizeReference($sectionKey));
         // Only get sections within that level. Do not get the level itself
         if (strpos($testSectionKey . '.', $reference) === 0 && $testSectionKey . '.' != $reference) {
             $section = $this->sections[$sectionKey];
             if ($maxDepth !== null && $section->getDepth() > $maxDepth) {
                 continue;
             }
             $sections[$sectionKey] = $section;
         }
     }
     return $sections;
 }