Debian Codegraph @

vendor/symfony/yaml/ParserState.php

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