1 | <?php |
||
2 | |||
3 | namespace Phing\Io; |
||
4 | |||
5 | /** |
||
6 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
7 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
8 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||
9 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||
10 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
11 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||
12 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
13 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
14 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
15 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
16 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
17 | * |
||
18 | * This software consists of voluntary contributions made by many individuals |
||
19 | * and is licensed under the LGPL. For more information please see |
||
20 | * <http://phing.info>. |
||
21 | */ |
||
22 | class PrintStream |
||
23 | { |
||
24 | /** |
||
25 | * @var OutputStream |
||
26 | */ |
||
27 | protected $out; |
||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private $autoFlush = false; |
||
32 | |||
33 | /** |
||
34 | * @var BufferedWriter |
||
35 | */ |
||
36 | private $textOut; |
||
37 | |||
38 | /** |
||
39 | * @param bool $autoFlush |
||
40 | */ |
||
41 | public function __construct(OutputStream $out, $autoFlush = false) |
||
42 | { |
||
43 | $this->out = $out; |
||
44 | $this->autoFlush = $autoFlush; |
||
45 | |||
46 | $this->textOut = new BufferedWriter(new OutputStreamWriter($out)); |
||
47 | } |
||
48 | |||
49 | public function println($value) |
||
50 | { |
||
51 | $this->prints($value); |
||
52 | $this->newLine(); |
||
53 | } |
||
54 | |||
55 | public function prints($value) |
||
56 | { |
||
57 | if (is_bool($value)) { |
||
58 | $value = true === $value ? 'true' : 'false'; |
||
59 | } |
||
60 | |||
61 | $this->write((string) $value); |
||
62 | } |
||
63 | |||
64 | private function newLine() |
||
65 | { |
||
66 | $this->textOut->newLine(); |
||
67 | |||
68 | if ($this->autoFlush) { |
||
69 | $this->textOut->flush(); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param string $buf |
||
75 | * @param int $off |
||
76 | * @param int $len |
||
77 | */ |
||
78 | private function write($buf, $off = null, $len = null) |
||
79 | { |
||
80 | $this->textOut->write($buf, $off, $len); |
||
81 | |||
82 | if ($this->autoFlush || $buff = '\n' && $this->autoFlush) { |
||
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
83 | $this->textOut->flush(); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 |