src/cultusrego.php
private function find_sections() {
    $sections = array();
    $level_memory = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $last_section = FALSE;

    // Match multiline comments
    preg_match_all('#\/\*((?:(?!\*\/).)*)\*\/#s', $this->code, $matches);

    foreach ($matches[1] as $match) {
      $section = array();
      $elements = $this->parse_match($match);

      if (isset($elements['title']) && isset($elements['level'])) {
        // Default htag to the lowest level htag
        $elements['htag'] = 'h6';

        // Find the depth of the level value
        $level_depth_arr = array_filter(explode('.', $elements['level']));
        $level_depth = count($level_depth_arr);
        if (isset($this->section_htags[$level_depth])) {
          $elements['htag'] = $this->section_htags[$level_depth];
        }

        // Reset the level memory to the depth of sub levels
        $level_memory = array_slice($level_memory, 0, $level_depth);
        $level_memory = array_pad($level_memory, 10, 0);

        // Set / unset and count up the levels
        foreach ($level_depth_arr as $key => $level) {
          if (is_numeric($level)) {
            $level_memory[$key] = $level;
          }
          else {
            // Only count up the last level
            if ($key > 0 && $key + 1 == $level_depth) {
              $level_memory[$key]++;
            }
            // Set the level depth
            $level_depth_arr[$key] = $level_memory[$key];
          }
        }
        $elements['level'] = implode('.', $level_depth_arr) . '.';

        $sections[$elements['level']] = $elements;
        $last_section = $elements['level'];
      }
      // If no title or level is provided scan for other styleguide elements
      // and append them to the previous section
      else if (!empty($elements)) {
        foreach ($elements as $element_label => $element_value) {
          $sections[$last_section][$element_label] = isset($sections[$last_section][$element_label])
            ? $sections[$last_section][$element_label] . "\n" . $element_value
            : $element_value;
        }
      }
    }

    ksort($sections);
    $this->build_section_tree($sections);
  }
private function find_sections() {
    $sections = array();
    $level_memory = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $last_section = FALSE;

    // Match multiline comments
    preg_match_all('#\/\*((?:(?!\*\/).)*)\*\/#s', $this->code, $matches);

    foreach ($matches[1] as $match) {
      $section = array();
      $elements = $this->parse_match($match);

      if (isset($elements['title']) && isset($elements['level'])) {
        // Default htag to the lowest level htag
        $elements['htag'] = 'h6';

        // Find the depth of the level value
        $level_depth_arr = array_filter(explode('.', $elements['level']));
        $level_depth = count($level_depth_arr);
        if (isset($this->section_htags[$level_depth])) {
          $elements['htag'] = $this->section_htags[$level_depth];
        }

        // Reset the level memory to the depth of sub levels
        $level_memory = array_slice($level_memory, 0, $level_depth);
        $level_memory = array_pad($level_memory, 10, 0);

        // Set / unset and count up the levels
        foreach ($level_depth_arr as $key => $level) {
          if (is_numeric($level)) {
            $level_memory[$key] = $level;
          }
          else {
            // Only count up the last level
            if ($key > 0 && $key + 1 == $level_depth) {
              $level_memory[$key]++;
            }
            // Set the level depth
            $level_depth_arr[$key] = $level_memory[$key];
          }
        }
        $elements['level'] = implode('.', $level_depth_arr) . '.';

        $sections[$elements['level']] = $elements;
        $last_section = $elements['level'];
      }
      // If no title or level is provided scan for other styleguide elements
      // and append them to the previous section
      else if (!empty($elements)) {
        foreach ($elements as $element_label => $element_value) {
          $sections[$last_section][$element_label] = isset($sections[$last_section][$element_label])
            ? $sections[$last_section][$element_label] . "\n" . $element_value
            : $element_value;
        }
      }
    }

    ksort($sections);
    $this->build_section_tree($sections);
  }
private function find_sections ( ) { $ sections = array ( ) ; $ level_memory = array ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ; $ last_section = FALSE ; // Match multiline comments preg_match_all ( '#\/\*((?:(?!\*\/).)*)\*\/#s' , $ this -> code , $ matches ) ; foreach ( $ matches [ 1 ] as $ match ) { $ section = array ( ) ; $ elements = $ this -> parse_match ( $ match ) ; if ( isset ( $ elements [ 'title' ] ) && isset ( $ elements [ 'level' ] ) ) { // Default htag to the lowest level htag $ elements [ 'htag' ] = 'h6' ; // Find the depth of the level value $ level_depth_arr = array_filter ( explode ( '.' , $ elements [ 'level' ] ) ) ; $ level_depth = count ( $ level_depth_arr ) ; if ( isset ( $ this -> section_htags [ $ level_depth ] ) ) { $ elements [ 'htag' ] = $ this -> section_htags [ $ level_depth ] ; } // Reset the level memory to the depth of sub levels $ level_memory = array_slice ( $ level_memory , 0 , $ level_depth ) ; $ level_memory = array_pad ( $ level_memory , 10 , 0 ) ; // Set / unset and count up the levels foreach ( $ level_depth_arr as $ key => $ level ) { if ( is_numeric ( $ level ) ) { $ level_memory [ $ key ] = $ level ; } else { // Only count up the last level if ( $ key > 0 && $ key + 1 == $ level_depth ) { $ level_memory [ $ key ] ++ ; } // Set the level depth $ level_depth_arr [ $ key ] = $ level_memory [ $ key ] ; } } $ elements [ 'level' ] = implode ( '.' , $ level_depth_arr ) . '.' ; $ sections [ $ elements [ 'level' ] ] = $ elements ; $ last_section = $ elements [ 'level' ] ; } // If no title or level is provided scan for other styleguide elements // and append them to the previous section else if ( ! empty ( $ elements ) ) { foreach ( $ elements as $ element_label => $ element_value ) { $ sections [ $ last_section ] [ $ element_label ] = isset ( $ sections [ $ last_section ] [ $ element_label ] ) ? $ sections [ $ last_section ] [ $ element_label ] . "\n" . $ element_value : $ element_value ; } } } ksort ( $ sections ) ; $ this -> build_section_tree ( $ sections ) ; }
Parse the provided code for valid styleguide sections
Parse the provided code for valid styleguide sections