Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / lib / Doctrine / ORM / Query / Printer.php
1 <?php
2 /*
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.
14  *
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>.
18  */
19
20 namespace Doctrine\ORM\Query;
21
22 /**
23  * A parse tree printer for Doctrine Query Language parser.
24  *
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
28  * @since       2.0
29  */
30 class Printer
31 {
32     /**
33      * Current indentation level
34      *
35      * @var int
36      */
37     protected $_indent = 0;
38
39     /**
40      * Defines whether parse tree is printed (default, false) or not (true).
41      *
42      * @var bool
43      */
44     protected $_silent;
45
46     /**
47      * Constructs a new parse tree printer.
48      *
49      * @param bool $silent Parse tree will not be printed if true.
50      */
51     public function __construct($silent = false)
52     {
53         $this->_silent = $silent;
54     }
55
56     /**
57      * Prints an opening parenthesis followed by production name and increases
58      * indentation level by one.
59      *
60      * This method is called before executing a production.
61      *
62      * @param string $name production name
63      */
64     public function startProduction($name)
65     {
66         $this->println('(' . $name);
67         $this->_indent++;
68     }
69
70     /**
71      * Decreases indentation level by one and prints a closing parenthesis.
72      *
73      * This method is called after executing a production.
74      */
75     public function endProduction()
76     {
77         $this->_indent--;
78         $this->println(')');
79     }
80
81     /**
82      * Prints text indented with spaces depending on current indentation level.
83      *
84      * @param string $str text
85      */
86     public function println($str)
87     {
88         if ( ! $this->_silent) {
89             echo str_repeat('    ', $this->_indent), $str, "\n";
90         }
91     }
92 }