private function Parser::getNextEmbedBlock in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/symfony/yaml/Symfony/Component/Yaml/Parser.php \Symfony\Component\Yaml\Parser::getNextEmbedBlock()
Returns the next embed block of YAML.
Parameters
int $indentation The indent level at which the block is to be read, or null for default:
bool $inSequence True if the enclosing data structure is a sequence:
Return value
string A YAML string
Throws
ParseException When indentation problem are detected
1 call to Parser::getNextEmbedBlock()
- Parser::doParse in vendor/
symfony/ yaml/ Parser.php
File
- vendor/
symfony/ yaml/ Parser.php, line 363
Class
- Parser
- Parser parses YAML strings to convert them to PHP arrays.
Namespace
Symfony\Component\YamlCode
private function getNextEmbedBlock($indentation = null, $inSequence = false) {
$oldLineIndentation = $this
->getCurrentLineIndentation();
$blockScalarIndentations = array();
if ($this
->isBlockScalarHeader()) {
$blockScalarIndentations[] = $this
->getCurrentLineIndentation();
}
if (!$this
->moveToNextLine()) {
return;
}
if (null === $indentation) {
$newIndent = $this
->getCurrentLineIndentation();
$unindentedEmbedBlock = $this
->isStringUnIndentedCollectionItem();
if (!$this
->isCurrentLineEmpty() && 0 === $newIndent && !$unindentedEmbedBlock) {
throw new ParseException('Indentation problem.', $this
->getRealCurrentLineNb() + 1, $this->currentLine);
}
}
else {
$newIndent = $indentation;
}
$data = array();
if ($this
->getCurrentLineIndentation() >= $newIndent) {
$data[] = substr($this->currentLine, $newIndent);
}
else {
$this
->moveToPreviousLine();
return;
}
if ($inSequence && $oldLineIndentation === $newIndent && isset($data[0][0]) && '-' === $data[0][0]) {
// the previous line contained a dash but no item content, this line is a sequence item with the same indentation
// and therefore no nested list or mapping
$this
->moveToPreviousLine();
return;
}
$isItUnindentedCollection = $this
->isStringUnIndentedCollectionItem();
if (empty($blockScalarIndentations) && $this
->isBlockScalarHeader()) {
$blockScalarIndentations[] = $this
->getCurrentLineIndentation();
}
$previousLineIndentation = $this
->getCurrentLineIndentation();
while ($this
->moveToNextLine()) {
$indent = $this
->getCurrentLineIndentation();
// terminate all block scalars that are more indented than the current line
if (!empty($blockScalarIndentations) && $indent < $previousLineIndentation && '' !== trim($this->currentLine)) {
foreach ($blockScalarIndentations as $key => $blockScalarIndentation) {
if ($blockScalarIndentation >= $this
->getCurrentLineIndentation()) {
unset($blockScalarIndentations[$key]);
}
}
}
if (empty($blockScalarIndentations) && !$this
->isCurrentLineComment() && $this
->isBlockScalarHeader()) {
$blockScalarIndentations[] = $this
->getCurrentLineIndentation();
}
$previousLineIndentation = $indent;
if ($isItUnindentedCollection && !$this
->isCurrentLineEmpty() && !$this
->isStringUnIndentedCollectionItem() && $newIndent === $indent) {
$this
->moveToPreviousLine();
break;
}
if ($this
->isCurrentLineBlank()) {
$data[] = substr($this->currentLine, $newIndent);
continue;
}
// we ignore "comment" lines only when we are not inside a scalar block
if (empty($blockScalarIndentations) && $this
->isCurrentLineComment()) {
// remember ignored comment lines (they are used later in nested
// parser calls to determine real line numbers)
//
// CAUTION: beware to not populate the global property here as it
// will otherwise influence the getRealCurrentLineNb() call here
// for consecutive comment lines and subsequent embedded blocks
$this->locallySkippedLineNumbers[] = $this
->getRealCurrentLineNb();
continue;
}
if ($indent >= $newIndent) {
$data[] = substr($this->currentLine, $newIndent);
}
elseif (0 == $indent) {
$this
->moveToPreviousLine();
break;
}
else {
throw new ParseException('Indentation problem.', $this
->getRealCurrentLineNb() + 1, $this->currentLine);
}
}
return implode("\n", $data);
}