-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathInputOutputAwareTrait.php
153 lines (135 loc) · 2.72 KB
/
InputOutputAwareTrait.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php declare(strict_types=1);
/**
* The file is part of inhere/console
*
* @author https://github.com/inhere
* @homepage https://github.com/inhere/php-console
* @license https://github.com/inhere/php-console/blob/master/LICENSE
*/
namespace Inhere\Console\Decorate;
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Toolkit\PFlag\FlagsParser;
/**
* Class InputOutputAwareTrait
*
* @package Inhere\Console\Decorate
*/
trait InputOutputAwareTrait
{
/**
* @var FlagsParser|null
*/
protected ?FlagsParser $flags;
/**
* @var Input|null
*/
protected ?Input $input;
/**
* @var Output|null
*/
protected ?Output $output;
/**
* @return string
*/
public function getScript(): string
{
return $this->input->getScriptFile();
}
/**
* @return string
*/
public function getWorkdir(): string
{
return $this->input->getWorkDir();
}
/**
* @return string
*/
public function getScriptName(): string
{
return $this->input->getScriptName();
}
/**
* @param string $question
* @param bool $nl
*
* @return string
*/
public function readln(string $question = '', bool $nl = false): string
{
return $this->input->readln($question, $nl);
}
/**
* @param mixed $message
*
* @return int
*/
public function write(mixed $message): int
{
return $this->output->write($message);
}
/**
* @param mixed $message
*
* @return int
*/
public function writeln(mixed $message): int
{
return $this->output->writeln($message);
}
/**
* @return Input
*/
public function getInput(): Input
{
return $this->input;
}
/**
* @param Input $input
*/
public function setInput(Input $input): void
{
$this->input = $input;
}
/**
* @return Output
*/
public function getOutput(): Output
{
return $this->output;
}
/**
* @param Output $output
*/
public function setOutput(Output $output): void
{
$this->output = $output;
}
/**
* @param Input $input
* @param Output $output
*
* @return static
*/
public function setInputOutput(Input $input, Output $output): static
{
$this->input = $input;
$this->output = $output;
return $this;
}
/**
* @return FlagsParser
*/
public function getFlags(): FlagsParser
{
return $this->flags;
}
/**
* @param FlagsParser $flags
*/
public function setFlags(FlagsParser $flags): void
{
$this->flags = $flags;
}
}