|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the webmozart/console package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
|
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 Webmozart\Console\IO; |
|
13
|
|
|
|
|
14
|
|
|
use Webmozart\Console\Api\Formatter\Formatter; |
|
15
|
|
|
use Webmozart\Console\Api\IO\Input; |
|
16
|
|
|
use Webmozart\Console\Api\IO\IO; |
|
17
|
|
|
use Webmozart\Console\Api\IO\Output; |
|
18
|
|
|
use Webmozart\Console\Formatter\PlainFormatter; |
|
19
|
|
|
use Webmozart\Console\IO\InputStream\StringInputStream; |
|
20
|
|
|
use Webmozart\Console\IO\OutputStream\BufferedOutputStream; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* An I/O that reads from and writes to a buffer. |
|
24
|
|
|
* |
|
25
|
|
|
* @since 1.0 |
|
26
|
|
|
* |
|
27
|
|
|
* @author Bernhard Schussek <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class BufferedIO extends IO |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Creates the I/O. |
|
33
|
|
|
* |
|
34
|
|
|
* @param string $inputData The data to return from the input. |
|
35
|
|
|
* @param Formatter $formatter The formatter to use. |
|
|
|
|
|
|
36
|
|
|
*/ |
|
37
|
158 |
|
public function __construct($inputData = '', Formatter $formatter = null) |
|
38
|
|
|
{ |
|
39
|
158 |
|
$formatter = $formatter ?: new PlainFormatter(); |
|
40
|
158 |
|
$input = new Input(new StringInputStream($inputData)); |
|
41
|
158 |
|
$output = new Output(new BufferedOutputStream(), $formatter); |
|
42
|
158 |
|
$errorOutput = new Output(new BufferedOutputStream(), $formatter); |
|
43
|
|
|
|
|
44
|
158 |
|
parent::__construct($input, $output, $errorOutput); |
|
45
|
158 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Sets the contents of the input buffer. |
|
49
|
|
|
* |
|
50
|
|
|
* @param string $data The input data. |
|
51
|
|
|
*/ |
|
52
|
3 |
|
public function setInput($data) |
|
53
|
|
|
{ |
|
54
|
3 |
|
$this->getInput()->getStream()->set($data); |
|
|
|
|
|
|
55
|
3 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Appends data to the input buffer. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $data The input data to append. |
|
61
|
|
|
*/ |
|
62
|
1 |
|
public function appendInput($data) |
|
63
|
|
|
{ |
|
64
|
1 |
|
$this->getInput()->getStream()->append($data); |
|
|
|
|
|
|
65
|
1 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Clears the input buffer. |
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function clearInput() |
|
71
|
|
|
{ |
|
72
|
1 |
|
$this->getInput()->getStream()->clear(); |
|
|
|
|
|
|
73
|
1 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns the contents of the output buffer. |
|
77
|
|
|
* |
|
78
|
|
|
* @return string The output data. |
|
79
|
|
|
*/ |
|
80
|
93 |
|
public function fetchOutput() |
|
81
|
|
|
{ |
|
82
|
93 |
|
return $this->getOutput()->getStream()->fetch(); |
|
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Clears the output buffer. |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function clearOutput() |
|
89
|
|
|
{ |
|
90
|
1 |
|
$this->getOutput()->getStream()->clear(); |
|
|
|
|
|
|
91
|
1 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Returns the contents of the error output buffer. |
|
95
|
|
|
* |
|
96
|
|
|
* @return string The data of the error output. |
|
97
|
|
|
*/ |
|
98
|
6 |
|
public function fetchErrors() |
|
99
|
|
|
{ |
|
100
|
6 |
|
return $this->getErrorOutput()->getStream()->fetch(); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Clears the error output buffer. |
|
105
|
|
|
*/ |
|
106
|
1 |
|
public function clearErrors() |
|
107
|
|
|
{ |
|
108
|
1 |
|
$this->getErrorOutput()->getStream()->clear(); |
|
|
|
|
|
|
109
|
1 |
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.