source: pro-violet-viettel/sourcecode/application/libraries/Doctrine/ORM/Query/Printer.php @ 345

Last change on this file since 345 was 345, checked in by quyenla, 11 years ago

collaborator page

File size: 2.6 KB
Line 
1<?php
2/*
3 *  $Id$
4 *
5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 *
17 * This software consists of voluntary contributions made by many individuals
18 * and is licensed under the LGPL. For more information, see
19 * <http://www.phpdoctrine.org>.
20 */
21
22namespace Doctrine\ORM\Query;
23
24/**
25 * A parse tree printer for Doctrine Query Language parser.
26 *
27 * @author      Janne Vanhala <jpvanhal@cc.hut.fi>
28 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
29 * @link        http://www.phpdoctrine.org
30 * @since       2.0
31 * @version     $Revision$
32 */
33class Printer
34{
35    /**
36     * Current indentation level
37     *
38     * @var int
39     */
40    protected $_indent = 0;
41
42    /**
43     * Defines whether parse tree is printed (default, false) or not (true).
44     *
45     * @var bool
46     */
47    protected $_silent;
48
49    /**
50     * Constructs a new parse tree printer.
51     *
52     * @param bool $silent Parse tree will not be printed if true.
53     */
54    public function __construct($silent = false)
55    {
56        $this->_silent = $silent;
57    }
58
59    /**
60     * Prints an opening parenthesis followed by production name and increases
61     * indentation level by one.
62     *
63     * This method is called before executing a production.
64     *
65     * @param string $name production name
66     */
67    public function startProduction($name)
68    {
69        $this->println('(' . $name);
70        $this->_indent++;
71    }
72
73    /**
74     * Decreases indentation level by one and prints a closing parenthesis.
75     *
76     * This method is called after executing a production.
77     */
78    public function endProduction()
79    {
80        $this->_indent--;
81        $this->println(')');
82    }
83
84    /**
85     * Prints text indented with spaces depending on current indentation level.
86     *
87     * @param string $str text
88     */
89    public function println($str)
90    {
91        if ( ! $this->_silent) {
92            echo str_repeat('    ', $this->_indent), $str, "\n";
93        }
94    }
95}
Note: See TracBrowser for help on using the repository browser.