| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Symfony package. |
| 5 |
* |
| 6 |
* (c) Fabien Potencier <fabien@symfony.com> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
namespace WindPressDeps\Symfony\Component\Yaml; |
| 12 |
|
| 13 |
use WindPressDeps\Symfony\Component\Yaml\Exception\ParseException; |
| 14 |
use WindPressDeps\Symfony\Component\Yaml\Tag\TaggedValue; |
| 15 |
/** |
| 16 |
* @internal |
| 17 |
*/ |
| 18 |
final class ParserState |
| 19 |
{ |
| 20 |
public $maxNestingLevel = Parser::DEFAULT_MAX_NESTING_LEVEL; |
| 21 |
public $currentNestingLevel = 0; |
| 22 |
public $maxAliasesForCollections = Parser::DEFAULT_MAX_ALIASES_FOR_COLLECTIONS; |
| 23 |
public $collectionAliasCount = 0; |
| 24 |
public $aliasesEnabled = \true; |
| 25 |
public function reset(): void |
| 26 |
{ |
| 27 |
$this->currentNestingLevel = 0; |
| 28 |
$this->collectionAliasCount = 0; |
| 29 |
$this->aliasesEnabled = \true; |
| 30 |
} |
| 31 |
public function enterNestingLevel(int $line, ?string $snippet, ?string $filename): void |
| 32 |
{ |
| 33 |
if (++$this->currentNestingLevel > $this->maxNestingLevel) { |
| 34 |
--$this->currentNestingLevel; |
| 35 |
throw new ParseException(sprintf('Maximum nesting depth of %d exceeded.', $this->maxNestingLevel), $line, $snippet, $filename); |
| 36 |
} |
| 37 |
} |
| 38 |
public function leaveNestingLevel(): void |
| 39 |
{ |
| 40 |
if ($this->currentNestingLevel > 0) { |
| 41 |
--$this->currentNestingLevel; |
| 42 |
} |
| 43 |
} |
| 44 |
/** |
| 45 |
* @param mixed $refValue |
| 46 |
*/ |
| 47 |
public function countAlias($refValue, int $line, ?string $snippet, ?string $filename): void |
| 48 |
{ |
| 49 |
if (!$this->aliasesEnabled) { |
| 50 |
throw new ParseException('Aliases are disabled.', $line, $snippet, $filename); |
| 51 |
} |
| 52 |
if ($refValue instanceof TaggedValue) { |
| 53 |
$refValue = $refValue->getValue(); |
| 54 |
} |
| 55 |
if (!\is_array($refValue) && !$refValue instanceof \stdClass) { |
| 56 |
return; |
| 57 |
} |
| 58 |
if (++$this->collectionAliasCount > $this->maxAliasesForCollections) { |
| 59 |
throw new ParseException(sprintf('Maximum number of collection aliases (%d) exceeded. This limit can be increased via the Parser constructor.', $this->maxAliasesForCollections), $line, $snippet, $filename); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|