Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / symfony / console / Symfony / Component / Console / Output / ConsoleOutput.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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\Console\Output;
13
14 use Symfony\Component\Console\Formatter\OutputFormatter;
15 use Symfony\Component\Console\Formatter\OutputFormatterInterface;
16 use Symfony\Component\Console\Output\ConsoleOutputInterface;
17
18 /**
19  * ConsoleOutput is the default class for all CLI output. It uses STDOUT.
20  *
21  * This class is a convenient wrapper around `StreamOutput`.
22  *
23  *     $output = new ConsoleOutput();
24  *
25  * This is equivalent to:
26  *
27  *     $output = new StreamOutput(fopen('php://stdout', 'w'));
28  *
29  * @author Fabien Potencier <fabien@symfony.com>
30  *
31  * @api
32  */
33 class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
34 {
35     private $stderr;
36
37     /**
38      * Constructor.
39      *
40      * @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL,
41      *                                   self::VERBOSITY_VERBOSE)
42      * @param Boolean         $decorated Whether to decorate messages or not (null for auto-guessing)
43      * @param OutputFormatter $formatter Output formatter instance
44      *
45      * @api
46      */
47     public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
48     {
49         $outputStream = 'php://stdout';
50         if (!$this->hasStdoutSupport()) {
51             $outputStream = 'php://output';
52         }
53
54         parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
55
56         $this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $formatter);
57     }
58
59     public function setDecorated($decorated)
60     {
61         parent::setDecorated($decorated);
62         $this->stderr->setDecorated($decorated);
63     }
64
65     public function setFormatter(OutputFormatterInterface $formatter)
66     {
67         parent::setFormatter($formatter);
68         $this->stderr->setFormatter($formatter);
69     }
70
71     public function setVerbosity($level)
72     {
73         parent::setVerbosity($level);
74         $this->stderr->setVerbosity($level);
75     }
76
77     /**
78      * @return OutputInterface
79      */
80     public function getErrorOutput()
81     {
82         return $this->stderr;
83     }
84
85     public function setErrorOutput(OutputInterface $error)
86     {
87         $this->stderr = $error;
88     }
89
90     /**
91      * Returns true if current environment supports writing console output to
92      * STDOUT.
93      *
94      * IBM iSeries (OS400) exhibits character-encoding issues when writing to
95      * STDOUT and doesn't properly convert ASCII to EBCDIC, resulting in garbage
96      * output.
97      *
98      * @return boolean
99      */
100     protected function hasStdoutSupport()
101     {
102         return ('OS400' != php_uname('s'));
103     }
104 }