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 int $maxNestingLevel = Parser::DEFAULT_MAX_NESTING_LEVEL;
23 public int $currentNestingLevel = 0;
24 public int $maxAliasesForCollections = Parser::DEFAULT_MAX_ALIASES_FOR_COLLECTIONS;
25 public int $collectionAliasCount = 0;
26 public bool $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 public function countAlias(mixed $refValue, int $line, ?string $snippet, ?string $filename): void
52 {
53 if (!$this->aliasesEnabled) {
54 throw new ParseException('Aliases are disabled.', $line, $snippet, $filename);
55 }
56
57 if ($refValue instanceof TaggedValue) {
58 $refValue = $refValue->getValue();
59 }
60
61 if (!\is_array($refValue) && !$refValue instanceof \stdClass) {
62 return;
63 }
64
65 if (++$this->collectionAliasCount > $this->maxAliasesForCollections) {
66 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);
67 }
68 }
69 }