3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\ORM\Query;
23 * A parse tree printer for Doctrine Query Language parser.
25 * @author Janne Vanhala <jpvanhal@cc.hut.fi>
26 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
27 * @link http://www.phpdoctrine.org
33 * Current indentation level
37 protected $_indent = 0;
40 * Defines whether parse tree is printed (default, false) or not (true).
47 * Constructs a new parse tree printer.
49 * @param bool $silent Parse tree will not be printed if true.
51 public function __construct($silent = false)
53 $this->_silent = $silent;
57 * Prints an opening parenthesis followed by production name and increases
58 * indentation level by one.
60 * This method is called before executing a production.
62 * @param string $name production name
64 public function startProduction($name)
66 $this->println('(' . $name);
71 * Decreases indentation level by one and prints a closing parenthesis.
73 * This method is called after executing a production.
75 public function endProduction()
82 * Prints text indented with spaces depending on current indentation level.
84 * @param string $str text
86 public function println($str)
88 if ( ! $this->_silent) {
89 echo str_repeat(' ', $this->_indent), $str, "\n";