protected static function _decodeYaml($currentIndent, &$lines)
    {
        $config   = array();
        $inIndent = false;
        while (list($n, $line) = each($lines)) {
            $lineno = $n + 1;

            $line = rtrim(preg_replace("/#.*$/", "", $line));
            if (strlen($line) == 0) {
                continue;
            }

            $indent = strspn($line, " ");

            // line without the spaces
            $line = trim($line);
            if (strlen($line) == 0) {
                continue;
            }

            if ($indent < $currentIndent) {
                // this level is done
                prev($lines);
                return $config;
            }

            if (!$inIndent) {
                $currentIndent = $indent;
                $inIndent      = true;
            }

            if (preg_match("/(?!-)([\w\-]+):\s*(.*)/", $line, $m)) {
                // key: value
                if (strlen($m[2])) {
                    // simple key: value
                    $value = preg_replace("/#.*$/", "", $m[2]);
                    $value = self::_parseValue($value);
                } else {
                    // key: and then values on new lines
                    $value = self::_decodeYaml($currentIndent + 1, $lines);
                    if (is_array($value) && !count($value)) {
                        $value = "";
                    }
                }
                $config[$m[1]] = $value;
            } elseif ($line[0] == "-") {
                // item in the list:
                // - FOO
                if (strlen($line) > 2) {
                    $value = substr($line, 2);

                    $config[] = self::_parseValue($value);
                } else {
                    $config[] = self::_decodeYaml($currentIndent + 1, $lines);
                }
            } else {

                throw new Zend_Config_Exception(sprintf(
                    'Error parsing YAML at line %d - unsupported syntax: "%s"',
                    $lineno, $line
                ));
            }
        }
        return $config;
    }
protected static function _decodeYaml($currentIndent, &$lines)
    {
        $config   = array();
        $inIndent = false;
        while (list($n, $line) = each($lines)) {
            $lineno = $n + 1;

            $line = rtrim(preg_replace("/#.*$/", "", $line));
            if (strlen($line) == 0) {
                continue;
            }

            $indent = strspn($line, " ");

            // line without the spaces
            $line = trim($line);
            if (strlen($line) == 0) {
                continue;
            }

            if ($indent < $currentIndent) {
                // this level is done
                prev($lines);
                return $config;
            }

            if (!$inIndent) {
                $currentIndent = $indent;
                $inIndent      = true;
            }

            if (preg_match("/(?!-)([\w\-]+):\s*(.*)/", $line, $m)) {
                // key: value
                if (strlen($m[2])) {
                    // simple key: value
                    $value = preg_replace("/#.*$/", "", $m[2]);
                    $value = self::_parseValue($value);
                } else {
                    // key: and then values on new lines
                    $value = self::_decodeYaml($currentIndent + 1, $lines);
                    if (is_array($value) && !count($value)) {
                        $value = "";
                    }
                }
                $config[$m[1]] = $value;
            } elseif ($line[0] == "-") {
                // item in the list:
                // - FOO
                if (strlen($line) > 2) {
                    $value = substr($line, 2);

                    $config[] = self::_parseValue($value);
                } else {
                    $config[] = self::_decodeYaml($currentIndent + 1, $lines);
                }
            } else {

                throw new Zend_Config_Exception(sprintf(
                    'Error parsing YAML at line %d - unsupported syntax: "%s"',
                    $lineno, $line
                ));
            }
        }
        return $config;
    }
protected static function _decodeYaml ( $ currentIndent , & $ lines ) { $ config = array ( ) ; $ inIndent = false ; while ( list ( $ n , $ line ) = each ( $ lines ) ) { $ lineno = $ n + 1 ; $ line = rtrim ( preg_replace ( "/#.*$/" , "" , $ line ) ) ; if ( strlen ( $ line ) == 0 ) { continue ; } $ indent = strspn ( $ line , " " ) ; // line without the spaces $ line = trim ( $ line ) ; if ( strlen ( $ line ) == 0 ) { continue ; } if ( $ indent < $ currentIndent ) { // this level is done prev ( $ lines ) ; return $ config ; } if ( ! $ inIndent ) { $ currentIndent = $ indent ; $ inIndent = true ; } if ( preg_match ( "/(?!-)([\w\-]+):\s*(.*)/" , $ line , $ m ) ) { // key: value if ( strlen ( $ m [ 2 ] ) ) { // simple key: value $ value = preg_replace ( "/#.*$/" , "" , $ m [ 2 ] ) ; $ value = self :: _parseValue ( $ value ) ; } else { // key: and then values on new lines $ value = self :: _decodeYaml ( $ currentIndent + 1 , $ lines ) ; if ( is_array ( $ value ) && ! count ( $ value ) ) { $ value = "" ; } } $ config [ $ m [ 1 ] ] = $ value ; } elseif ( $ line [ 0 ] == "-" ) { // item in the list: // - FOO if ( strlen ( $ line ) > 2 ) { $ value = substr ( $ line , 2 ) ; $ config [ ] = self :: _parseValue ( $ value ) ; } else { $ config [ ] = self :: _decodeYaml ( $ currentIndent + 1 , $ lines ) ; } } else { throw new Zend_Config_Exception ( sprintf ( 'Error parsing YAML at line %d - unsupported syntax: "%s"' , $ lineno , $ line ) ) ; } } return $ config ; }
Service function to decode YAML

@param  int $currentIndent Current indent level
@param  array $lines  YAML lines
@return array|string
Service function to decode YAML