1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nyx |
4
|
|
|
* |
5
|
|
|
* (The MIT license) |
6
|
|
|
* Copyright (c) 2016 Luke Steadman |
7
|
|
|
* |
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9
|
|
|
* of this software and associated * documentation files (the "Software"), to |
10
|
|
|
* deal in the Software without restriction, including without limitation the |
11
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
12
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is |
13
|
|
|
* furnished to do so, subject to the following conditions: |
14
|
|
|
* The above copyright notice and this permission notice shall be included in |
15
|
|
|
* all copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
22
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
23
|
|
|
* IN THE SOFTWARE. |
24
|
|
|
* |
25
|
|
|
* @package Nyx |
26
|
|
|
*/ |
27
|
|
|
namespace Nyx; |
28
|
|
|
|
29
|
|
|
class Console implements OutputInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Array of messages |
33
|
|
|
* |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $buffer = array(); |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Write the message. |
40
|
|
|
* |
41
|
|
|
* @param string $msg |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
2 |
|
public function write($msg) |
45
|
|
|
{ |
46
|
2 |
|
print($msg) . PHP_EOL; |
47
|
2 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Clear the buffer. |
51
|
|
|
* |
52
|
|
|
* $write allows the developer to flush the buffer without outputting. |
53
|
|
|
* |
54
|
|
|
* @param bool $write |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
2 |
|
public function flush($write = true) |
58
|
|
|
{ |
59
|
2 |
|
if (!$write) { |
60
|
1 |
|
$this->buffer = array(); |
61
|
1 |
|
} |
62
|
|
|
|
63
|
2 |
|
foreach ((array)$this->buffer as $msg) { |
64
|
1 |
|
$this->write($msg); |
65
|
2 |
|
} |
66
|
2 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Buffer a message ready for output |
70
|
|
|
* |
71
|
|
|
* @param string $msg |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
2 |
|
public function buffer($msg) |
75
|
|
|
{ |
76
|
2 |
|
if (is_string($msg)) { |
77
|
2 |
|
$this->buffer[] = $msg; |
78
|
2 |
|
} |
79
|
2 |
|
} |
80
|
|
|
} |
81
|
|
|
|