summaryrefslogtreecommitdiff
path: root/vendor/doctrine/orm/src/Query/Printer.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/orm/src/Query/Printer.php')
-rw-r--r--vendor/doctrine/orm/src/Query/Printer.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Query/Printer.php b/vendor/doctrine/orm/src/Query/Printer.php
new file mode 100644
index 0000000..db1f159
--- /dev/null
+++ b/vendor/doctrine/orm/src/Query/Printer.php
@@ -0,0 +1,64 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\ORM\Query;
6
7use function str_repeat;
8
9/**
10 * A parse tree printer for Doctrine Query Language parser.
11 *
12 * @link http://www.phpdoctrine.org
13 */
14class Printer
15{
16 /** Current indentation level */
17 protected int $indent = 0;
18
19 /**
20 * Constructs a new parse tree printer.
21 *
22 * @param bool $silent Parse tree will not be printed if true.
23 */
24 public function __construct(protected bool $silent = false)
25 {
26 }
27
28 /**
29 * Prints an opening parenthesis followed by production name and increases
30 * indentation level by one.
31 *
32 * This method is called before executing a production.
33 *
34 * @param string $name Production name.
35 */
36 public function startProduction(string $name): void
37 {
38 $this->println('(' . $name);
39 $this->indent++;
40 }
41
42 /**
43 * Decreases indentation level by one and prints a closing parenthesis.
44 *
45 * This method is called after executing a production.
46 */
47 public function endProduction(): void
48 {
49 $this->indent--;
50 $this->println(')');
51 }
52
53 /**
54 * Prints text indented with spaces depending on current indentation level.
55 *
56 * @param string $str The text.
57 */
58 public function println(string $str): void
59 {
60 if (! $this->silent) {
61 echo str_repeat(' ', $this->indent), $str, "\n";
62 }
63 }
64}