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 Symfony\Component\Console\Application; |
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\AnsiFormatter; |
19
|
|
|
use Webmozart\Console\Formatter\PlainFormatter; |
20
|
|
|
use Webmozart\Console\IO\InputStream\StandardInputStream; |
21
|
|
|
use Webmozart\Console\IO\OutputStream\ErrorOutputStream; |
22
|
|
|
use Webmozart\Console\IO\OutputStream\StandardOutputStream; |
23
|
|
|
use Webmozart\Console\UI\Rectangle; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* An I/O that reads from/prints to the console. |
27
|
|
|
* |
28
|
|
|
* @since 1.0 |
29
|
|
|
* |
30
|
|
|
* @author Bernhard Schussek <[email protected]> |
31
|
|
|
*/ |
32
|
|
|
class ConsoleIO extends IO |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Creates the I/O. |
36
|
|
|
* |
37
|
|
|
* @param Input $input The standard input. |
|
|
|
|
38
|
|
|
* @param Output $output The standard output. |
|
|
|
|
39
|
|
|
* @param Output $errorOutput The error output. |
|
|
|
|
40
|
|
|
*/ |
41
|
138 |
|
public function __construct(Input $input = null, Output $output = null, Output $errorOutput = null) |
42
|
|
|
{ |
43
|
138 |
|
if (null === $input) { |
44
|
138 |
|
$inputStream = new StandardInputStream(); |
45
|
138 |
|
$input = new Input($inputStream); |
46
|
|
|
} |
47
|
|
|
|
48
|
138 |
View Code Duplication |
if (null === $output) { |
|
|
|
|
49
|
138 |
|
$outputStream = new StandardOutputStream(); |
50
|
138 |
|
$formatter = $outputStream->supportsAnsi() ? new AnsiFormatter() : new PlainFormatter(); |
51
|
138 |
|
$output = new Output($outputStream, $formatter); |
52
|
|
|
} |
53
|
|
|
|
54
|
138 |
View Code Duplication |
if (null === $errorOutput) { |
|
|
|
|
55
|
138 |
|
$errorStream = new ErrorOutputStream(); |
56
|
138 |
|
$formatter = $errorStream->supportsAnsi() ? new AnsiFormatter() : new PlainFormatter(); |
57
|
138 |
|
$errorOutput = new Output($errorStream, $formatter); |
58
|
|
|
} |
59
|
|
|
|
60
|
138 |
|
parent::__construct($input, $output, $errorOutput); |
61
|
138 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
15 |
|
protected function getDefaultTerminalDimensions() |
67
|
|
|
{ |
68
|
15 |
|
$application = new Application(); |
69
|
|
|
|
70
|
15 |
|
list($width, $height) = $application->getTerminalDimensions(); |
71
|
|
|
|
72
|
15 |
|
return new Rectangle($width ?: 80, $height ?: 20); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for
@param
annotations 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.