@@ -18,115 +18,115 @@ |
||
18 | 18 | */ |
19 | 19 | interface StyleInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Formats a command title. |
|
23 | - */ |
|
24 | - public function title(string $message); |
|
25 | - |
|
26 | - /** |
|
27 | - * Formats a section title. |
|
28 | - */ |
|
29 | - public function section(string $message); |
|
30 | - |
|
31 | - /** |
|
32 | - * Formats a list. |
|
33 | - */ |
|
34 | - public function listing(array $elements); |
|
35 | - |
|
36 | - /** |
|
37 | - * Formats informational text. |
|
38 | - * |
|
39 | - * @param string|array $message |
|
40 | - */ |
|
41 | - public function text($message); |
|
42 | - |
|
43 | - /** |
|
44 | - * Formats a success result bar. |
|
45 | - * |
|
46 | - * @param string|array $message |
|
47 | - */ |
|
48 | - public function success($message); |
|
49 | - |
|
50 | - /** |
|
51 | - * Formats an error result bar. |
|
52 | - * |
|
53 | - * @param string|array $message |
|
54 | - */ |
|
55 | - public function error($message); |
|
56 | - |
|
57 | - /** |
|
58 | - * Formats an warning result bar. |
|
59 | - * |
|
60 | - * @param string|array $message |
|
61 | - */ |
|
62 | - public function warning($message); |
|
63 | - |
|
64 | - /** |
|
65 | - * Formats a note admonition. |
|
66 | - * |
|
67 | - * @param string|array $message |
|
68 | - */ |
|
69 | - public function note($message); |
|
70 | - |
|
71 | - /** |
|
72 | - * Formats a caution admonition. |
|
73 | - * |
|
74 | - * @param string|array $message |
|
75 | - */ |
|
76 | - public function caution($message); |
|
77 | - |
|
78 | - /** |
|
79 | - * Formats a table. |
|
80 | - */ |
|
81 | - public function table(array $headers, array $rows); |
|
82 | - |
|
83 | - /** |
|
84 | - * Asks a question. |
|
85 | - * |
|
86 | - * @return mixed |
|
87 | - */ |
|
88 | - public function ask(string $question, string $default = null, callable $validator = null); |
|
89 | - |
|
90 | - /** |
|
91 | - * Asks a question with the user input hidden. |
|
92 | - * |
|
93 | - * @return mixed |
|
94 | - */ |
|
95 | - public function askHidden(string $question, callable $validator = null); |
|
96 | - |
|
97 | - /** |
|
98 | - * Asks for confirmation. |
|
99 | - * |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - public function confirm(string $question, bool $default = true); |
|
103 | - |
|
104 | - /** |
|
105 | - * Asks a choice question. |
|
106 | - * |
|
107 | - * @param string|int|null $default |
|
108 | - * |
|
109 | - * @return mixed |
|
110 | - */ |
|
111 | - public function choice(string $question, array $choices, $default = null); |
|
112 | - |
|
113 | - /** |
|
114 | - * Add newline(s). |
|
115 | - */ |
|
116 | - public function newLine(int $count = 1); |
|
117 | - |
|
118 | - /** |
|
119 | - * Starts the progress output. |
|
120 | - */ |
|
121 | - public function progressStart(int $max = 0); |
|
122 | - |
|
123 | - /** |
|
124 | - * Advances the progress output X steps. |
|
125 | - */ |
|
126 | - public function progressAdvance(int $step = 1); |
|
127 | - |
|
128 | - /** |
|
129 | - * Finishes the progress output. |
|
130 | - */ |
|
131 | - public function progressFinish(); |
|
21 | + /** |
|
22 | + * Formats a command title. |
|
23 | + */ |
|
24 | + public function title(string $message); |
|
25 | + |
|
26 | + /** |
|
27 | + * Formats a section title. |
|
28 | + */ |
|
29 | + public function section(string $message); |
|
30 | + |
|
31 | + /** |
|
32 | + * Formats a list. |
|
33 | + */ |
|
34 | + public function listing(array $elements); |
|
35 | + |
|
36 | + /** |
|
37 | + * Formats informational text. |
|
38 | + * |
|
39 | + * @param string|array $message |
|
40 | + */ |
|
41 | + public function text($message); |
|
42 | + |
|
43 | + /** |
|
44 | + * Formats a success result bar. |
|
45 | + * |
|
46 | + * @param string|array $message |
|
47 | + */ |
|
48 | + public function success($message); |
|
49 | + |
|
50 | + /** |
|
51 | + * Formats an error result bar. |
|
52 | + * |
|
53 | + * @param string|array $message |
|
54 | + */ |
|
55 | + public function error($message); |
|
56 | + |
|
57 | + /** |
|
58 | + * Formats an warning result bar. |
|
59 | + * |
|
60 | + * @param string|array $message |
|
61 | + */ |
|
62 | + public function warning($message); |
|
63 | + |
|
64 | + /** |
|
65 | + * Formats a note admonition. |
|
66 | + * |
|
67 | + * @param string|array $message |
|
68 | + */ |
|
69 | + public function note($message); |
|
70 | + |
|
71 | + /** |
|
72 | + * Formats a caution admonition. |
|
73 | + * |
|
74 | + * @param string|array $message |
|
75 | + */ |
|
76 | + public function caution($message); |
|
77 | + |
|
78 | + /** |
|
79 | + * Formats a table. |
|
80 | + */ |
|
81 | + public function table(array $headers, array $rows); |
|
82 | + |
|
83 | + /** |
|
84 | + * Asks a question. |
|
85 | + * |
|
86 | + * @return mixed |
|
87 | + */ |
|
88 | + public function ask(string $question, string $default = null, callable $validator = null); |
|
89 | + |
|
90 | + /** |
|
91 | + * Asks a question with the user input hidden. |
|
92 | + * |
|
93 | + * @return mixed |
|
94 | + */ |
|
95 | + public function askHidden(string $question, callable $validator = null); |
|
96 | + |
|
97 | + /** |
|
98 | + * Asks for confirmation. |
|
99 | + * |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + public function confirm(string $question, bool $default = true); |
|
103 | + |
|
104 | + /** |
|
105 | + * Asks a choice question. |
|
106 | + * |
|
107 | + * @param string|int|null $default |
|
108 | + * |
|
109 | + * @return mixed |
|
110 | + */ |
|
111 | + public function choice(string $question, array $choices, $default = null); |
|
112 | + |
|
113 | + /** |
|
114 | + * Add newline(s). |
|
115 | + */ |
|
116 | + public function newLine(int $count = 1); |
|
117 | + |
|
118 | + /** |
|
119 | + * Starts the progress output. |
|
120 | + */ |
|
121 | + public function progressStart(int $max = 0); |
|
122 | + |
|
123 | + /** |
|
124 | + * Advances the progress output X steps. |
|
125 | + */ |
|
126 | + public function progressAdvance(int $step = 1); |
|
127 | + |
|
128 | + /** |
|
129 | + * Finishes the progress output. |
|
130 | + */ |
|
131 | + public function progressFinish(); |
|
132 | 132 | } |
@@ -21,85 +21,85 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Formats a command title. |
23 | 23 | */ |
24 | - public function title(string $message); |
|
24 | + public function title( string $message ); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Formats a section title. |
28 | 28 | */ |
29 | - public function section(string $message); |
|
29 | + public function section( string $message ); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Formats a list. |
33 | 33 | */ |
34 | - public function listing(array $elements); |
|
34 | + public function listing( array $elements ); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Formats informational text. |
38 | 38 | * |
39 | 39 | * @param string|array $message |
40 | 40 | */ |
41 | - public function text($message); |
|
41 | + public function text( $message ); |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Formats a success result bar. |
45 | 45 | * |
46 | 46 | * @param string|array $message |
47 | 47 | */ |
48 | - public function success($message); |
|
48 | + public function success( $message ); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Formats an error result bar. |
52 | 52 | * |
53 | 53 | * @param string|array $message |
54 | 54 | */ |
55 | - public function error($message); |
|
55 | + public function error( $message ); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Formats an warning result bar. |
59 | 59 | * |
60 | 60 | * @param string|array $message |
61 | 61 | */ |
62 | - public function warning($message); |
|
62 | + public function warning( $message ); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Formats a note admonition. |
66 | 66 | * |
67 | 67 | * @param string|array $message |
68 | 68 | */ |
69 | - public function note($message); |
|
69 | + public function note( $message ); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Formats a caution admonition. |
73 | 73 | * |
74 | 74 | * @param string|array $message |
75 | 75 | */ |
76 | - public function caution($message); |
|
76 | + public function caution( $message ); |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Formats a table. |
80 | 80 | */ |
81 | - public function table(array $headers, array $rows); |
|
81 | + public function table( array $headers, array $rows ); |
|
82 | 82 | |
83 | 83 | /** |
84 | 84 | * Asks a question. |
85 | 85 | * |
86 | 86 | * @return mixed |
87 | 87 | */ |
88 | - public function ask(string $question, string $default = null, callable $validator = null); |
|
88 | + public function ask( string $question, string $default = null, callable $validator = null ); |
|
89 | 89 | |
90 | 90 | /** |
91 | 91 | * Asks a question with the user input hidden. |
92 | 92 | * |
93 | 93 | * @return mixed |
94 | 94 | */ |
95 | - public function askHidden(string $question, callable $validator = null); |
|
95 | + public function askHidden( string $question, callable $validator = null ); |
|
96 | 96 | |
97 | 97 | /** |
98 | 98 | * Asks for confirmation. |
99 | 99 | * |
100 | 100 | * @return bool |
101 | 101 | */ |
102 | - public function confirm(string $question, bool $default = true); |
|
102 | + public function confirm( string $question, bool $default = true ); |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * Asks a choice question. |
@@ -108,22 +108,22 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return mixed |
110 | 110 | */ |
111 | - public function choice(string $question, array $choices, $default = null); |
|
111 | + public function choice( string $question, array $choices, $default = null ); |
|
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Add newline(s). |
115 | 115 | */ |
116 | - public function newLine(int $count = 1); |
|
116 | + public function newLine( int $count = 1 ); |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * Starts the progress output. |
120 | 120 | */ |
121 | - public function progressStart(int $max = 0); |
|
121 | + public function progressStart( int $max = 0 ); |
|
122 | 122 | |
123 | 123 | /** |
124 | 124 | * Advances the progress output X steps. |
125 | 125 | */ |
126 | - public function progressAdvance(int $step = 1); |
|
126 | + public function progressAdvance( int $step = 1 ); |
|
127 | 127 | |
128 | 128 | /** |
129 | 129 | * Finishes the progress output. |
@@ -16,8 +16,7 @@ |
||
16 | 16 | * |
17 | 17 | * @author Kevin Bond <[email protected]> |
18 | 18 | */ |
19 | -interface StyleInterface |
|
20 | -{ |
|
19 | +interface StyleInterface { |
|
21 | 20 | /** |
22 | 21 | * Formats a command title. |
23 | 22 | */ |
@@ -23,131 +23,131 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class OutputStyle implements OutputInterface, StyleInterface |
25 | 25 | { |
26 | - private $output; |
|
27 | - |
|
28 | - public function __construct(OutputInterface $output) |
|
29 | - { |
|
30 | - $this->output = $output; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * {@inheritdoc} |
|
35 | - */ |
|
36 | - public function newLine(int $count = 1) |
|
37 | - { |
|
38 | - $this->output->write(str_repeat(\PHP_EOL, $count)); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @return ProgressBar |
|
43 | - */ |
|
44 | - public function createProgressBar(int $max = 0) |
|
45 | - { |
|
46 | - return new ProgressBar($this->output, $max); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) |
|
53 | - { |
|
54 | - $this->output->write($messages, $newline, $type); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * {@inheritdoc} |
|
59 | - */ |
|
60 | - public function writeln($messages, int $type = self::OUTPUT_NORMAL) |
|
61 | - { |
|
62 | - $this->output->writeln($messages, $type); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * {@inheritdoc} |
|
67 | - */ |
|
68 | - public function setVerbosity(int $level) |
|
69 | - { |
|
70 | - $this->output->setVerbosity($level); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * {@inheritdoc} |
|
75 | - */ |
|
76 | - public function getVerbosity() |
|
77 | - { |
|
78 | - return $this->output->getVerbosity(); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * {@inheritdoc} |
|
83 | - */ |
|
84 | - public function setDecorated(bool $decorated) |
|
85 | - { |
|
86 | - $this->output->setDecorated($decorated); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * {@inheritdoc} |
|
91 | - */ |
|
92 | - public function isDecorated() |
|
93 | - { |
|
94 | - return $this->output->isDecorated(); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * {@inheritdoc} |
|
99 | - */ |
|
100 | - public function setFormatter(OutputFormatterInterface $formatter) |
|
101 | - { |
|
102 | - $this->output->setFormatter($formatter); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * {@inheritdoc} |
|
107 | - */ |
|
108 | - public function getFormatter() |
|
109 | - { |
|
110 | - return $this->output->getFormatter(); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * {@inheritdoc} |
|
115 | - */ |
|
116 | - public function isQuiet() |
|
117 | - { |
|
118 | - return $this->output->isQuiet(); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * {@inheritdoc} |
|
123 | - */ |
|
124 | - public function isVerbose() |
|
125 | - { |
|
126 | - return $this->output->isVerbose(); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * {@inheritdoc} |
|
131 | - */ |
|
132 | - public function isVeryVerbose() |
|
133 | - { |
|
134 | - return $this->output->isVeryVerbose(); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * {@inheritdoc} |
|
139 | - */ |
|
140 | - public function isDebug() |
|
141 | - { |
|
142 | - return $this->output->isDebug(); |
|
143 | - } |
|
144 | - |
|
145 | - protected function getErrorOutput() |
|
146 | - { |
|
147 | - if (!$this->output instanceof ConsoleOutputInterface) { |
|
148 | - return $this->output; |
|
149 | - } |
|
150 | - |
|
151 | - return $this->output->getErrorOutput(); |
|
152 | - } |
|
26 | + private $output; |
|
27 | + |
|
28 | + public function __construct(OutputInterface $output) |
|
29 | + { |
|
30 | + $this->output = $output; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * {@inheritdoc} |
|
35 | + */ |
|
36 | + public function newLine(int $count = 1) |
|
37 | + { |
|
38 | + $this->output->write(str_repeat(\PHP_EOL, $count)); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @return ProgressBar |
|
43 | + */ |
|
44 | + public function createProgressBar(int $max = 0) |
|
45 | + { |
|
46 | + return new ProgressBar($this->output, $max); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) |
|
53 | + { |
|
54 | + $this->output->write($messages, $newline, $type); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * {@inheritdoc} |
|
59 | + */ |
|
60 | + public function writeln($messages, int $type = self::OUTPUT_NORMAL) |
|
61 | + { |
|
62 | + $this->output->writeln($messages, $type); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * {@inheritdoc} |
|
67 | + */ |
|
68 | + public function setVerbosity(int $level) |
|
69 | + { |
|
70 | + $this->output->setVerbosity($level); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * {@inheritdoc} |
|
75 | + */ |
|
76 | + public function getVerbosity() |
|
77 | + { |
|
78 | + return $this->output->getVerbosity(); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * {@inheritdoc} |
|
83 | + */ |
|
84 | + public function setDecorated(bool $decorated) |
|
85 | + { |
|
86 | + $this->output->setDecorated($decorated); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * {@inheritdoc} |
|
91 | + */ |
|
92 | + public function isDecorated() |
|
93 | + { |
|
94 | + return $this->output->isDecorated(); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * {@inheritdoc} |
|
99 | + */ |
|
100 | + public function setFormatter(OutputFormatterInterface $formatter) |
|
101 | + { |
|
102 | + $this->output->setFormatter($formatter); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * {@inheritdoc} |
|
107 | + */ |
|
108 | + public function getFormatter() |
|
109 | + { |
|
110 | + return $this->output->getFormatter(); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * {@inheritdoc} |
|
115 | + */ |
|
116 | + public function isQuiet() |
|
117 | + { |
|
118 | + return $this->output->isQuiet(); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * {@inheritdoc} |
|
123 | + */ |
|
124 | + public function isVerbose() |
|
125 | + { |
|
126 | + return $this->output->isVerbose(); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * {@inheritdoc} |
|
131 | + */ |
|
132 | + public function isVeryVerbose() |
|
133 | + { |
|
134 | + return $this->output->isVeryVerbose(); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * {@inheritdoc} |
|
139 | + */ |
|
140 | + public function isDebug() |
|
141 | + { |
|
142 | + return $this->output->isDebug(); |
|
143 | + } |
|
144 | + |
|
145 | + protected function getErrorOutput() |
|
146 | + { |
|
147 | + if (!$this->output instanceof ConsoleOutputInterface) { |
|
148 | + return $this->output; |
|
149 | + } |
|
150 | + |
|
151 | + return $this->output->getErrorOutput(); |
|
152 | + } |
|
153 | 153 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | { |
26 | 26 | private $output; |
27 | 27 | |
28 | - public function __construct(OutputInterface $output) |
|
28 | + public function __construct( OutputInterface $output ) |
|
29 | 29 | { |
30 | 30 | $this->output = $output; |
31 | 31 | } |
@@ -33,41 +33,41 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * {@inheritdoc} |
35 | 35 | */ |
36 | - public function newLine(int $count = 1) |
|
36 | + public function newLine( int $count = 1 ) |
|
37 | 37 | { |
38 | - $this->output->write(str_repeat(\PHP_EOL, $count)); |
|
38 | + $this->output->write( str_repeat( \PHP_EOL, $count ) ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @return ProgressBar |
43 | 43 | */ |
44 | - public function createProgressBar(int $max = 0) |
|
44 | + public function createProgressBar( int $max = 0 ) |
|
45 | 45 | { |
46 | - return new ProgressBar($this->output, $max); |
|
46 | + return new ProgressBar( $this->output, $max ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * {@inheritdoc} |
51 | 51 | */ |
52 | - public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) |
|
52 | + public function write( $messages, bool $newline = false, int $type = self::OUTPUT_NORMAL ) |
|
53 | 53 | { |
54 | - $this->output->write($messages, $newline, $type); |
|
54 | + $this->output->write( $messages, $newline, $type ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * {@inheritdoc} |
59 | 59 | */ |
60 | - public function writeln($messages, int $type = self::OUTPUT_NORMAL) |
|
60 | + public function writeln( $messages, int $type = self::OUTPUT_NORMAL ) |
|
61 | 61 | { |
62 | - $this->output->writeln($messages, $type); |
|
62 | + $this->output->writeln( $messages, $type ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * {@inheritdoc} |
67 | 67 | */ |
68 | - public function setVerbosity(int $level) |
|
68 | + public function setVerbosity( int $level ) |
|
69 | 69 | { |
70 | - $this->output->setVerbosity($level); |
|
70 | + $this->output->setVerbosity( $level ); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -81,9 +81,9 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * {@inheritdoc} |
83 | 83 | */ |
84 | - public function setDecorated(bool $decorated) |
|
84 | + public function setDecorated( bool $decorated ) |
|
85 | 85 | { |
86 | - $this->output->setDecorated($decorated); |
|
86 | + $this->output->setDecorated( $decorated ); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | /** |
98 | 98 | * {@inheritdoc} |
99 | 99 | */ |
100 | - public function setFormatter(OutputFormatterInterface $formatter) |
|
100 | + public function setFormatter( OutputFormatterInterface $formatter ) |
|
101 | 101 | { |
102 | - $this->output->setFormatter($formatter); |
|
102 | + $this->output->setFormatter( $formatter ); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | |
145 | 145 | protected function getErrorOutput() |
146 | 146 | { |
147 | - if (!$this->output instanceof ConsoleOutputInterface) { |
|
147 | + if ( ! $this->output instanceof ConsoleOutputInterface ) { |
|
148 | 148 | return $this->output; |
149 | 149 | } |
150 | 150 |
@@ -25,125 +25,109 @@ |
||
25 | 25 | { |
26 | 26 | private $output; |
27 | 27 | |
28 | - public function __construct(OutputInterface $output) |
|
29 | - { |
|
28 | + public function __construct(OutputInterface $output) { |
|
30 | 29 | $this->output = $output; |
31 | 30 | } |
32 | 31 | |
33 | 32 | /** |
34 | 33 | * {@inheritdoc} |
35 | 34 | */ |
36 | - public function newLine(int $count = 1) |
|
37 | - { |
|
35 | + public function newLine(int $count = 1) { |
|
38 | 36 | $this->output->write(str_repeat(\PHP_EOL, $count)); |
39 | 37 | } |
40 | 38 | |
41 | 39 | /** |
42 | 40 | * @return ProgressBar |
43 | 41 | */ |
44 | - public function createProgressBar(int $max = 0) |
|
45 | - { |
|
42 | + public function createProgressBar(int $max = 0) { |
|
46 | 43 | return new ProgressBar($this->output, $max); |
47 | 44 | } |
48 | 45 | |
49 | 46 | /** |
50 | 47 | * {@inheritdoc} |
51 | 48 | */ |
52 | - public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) |
|
53 | - { |
|
49 | + public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) { |
|
54 | 50 | $this->output->write($messages, $newline, $type); |
55 | 51 | } |
56 | 52 | |
57 | 53 | /** |
58 | 54 | * {@inheritdoc} |
59 | 55 | */ |
60 | - public function writeln($messages, int $type = self::OUTPUT_NORMAL) |
|
61 | - { |
|
56 | + public function writeln($messages, int $type = self::OUTPUT_NORMAL) { |
|
62 | 57 | $this->output->writeln($messages, $type); |
63 | 58 | } |
64 | 59 | |
65 | 60 | /** |
66 | 61 | * {@inheritdoc} |
67 | 62 | */ |
68 | - public function setVerbosity(int $level) |
|
69 | - { |
|
63 | + public function setVerbosity(int $level) { |
|
70 | 64 | $this->output->setVerbosity($level); |
71 | 65 | } |
72 | 66 | |
73 | 67 | /** |
74 | 68 | * {@inheritdoc} |
75 | 69 | */ |
76 | - public function getVerbosity() |
|
77 | - { |
|
70 | + public function getVerbosity() { |
|
78 | 71 | return $this->output->getVerbosity(); |
79 | 72 | } |
80 | 73 | |
81 | 74 | /** |
82 | 75 | * {@inheritdoc} |
83 | 76 | */ |
84 | - public function setDecorated(bool $decorated) |
|
85 | - { |
|
77 | + public function setDecorated(bool $decorated) { |
|
86 | 78 | $this->output->setDecorated($decorated); |
87 | 79 | } |
88 | 80 | |
89 | 81 | /** |
90 | 82 | * {@inheritdoc} |
91 | 83 | */ |
92 | - public function isDecorated() |
|
93 | - { |
|
84 | + public function isDecorated() { |
|
94 | 85 | return $this->output->isDecorated(); |
95 | 86 | } |
96 | 87 | |
97 | 88 | /** |
98 | 89 | * {@inheritdoc} |
99 | 90 | */ |
100 | - public function setFormatter(OutputFormatterInterface $formatter) |
|
101 | - { |
|
91 | + public function setFormatter(OutputFormatterInterface $formatter) { |
|
102 | 92 | $this->output->setFormatter($formatter); |
103 | 93 | } |
104 | 94 | |
105 | 95 | /** |
106 | 96 | * {@inheritdoc} |
107 | 97 | */ |
108 | - public function getFormatter() |
|
109 | - { |
|
98 | + public function getFormatter() { |
|
110 | 99 | return $this->output->getFormatter(); |
111 | 100 | } |
112 | 101 | |
113 | 102 | /** |
114 | 103 | * {@inheritdoc} |
115 | 104 | */ |
116 | - public function isQuiet() |
|
117 | - { |
|
105 | + public function isQuiet() { |
|
118 | 106 | return $this->output->isQuiet(); |
119 | 107 | } |
120 | 108 | |
121 | 109 | /** |
122 | 110 | * {@inheritdoc} |
123 | 111 | */ |
124 | - public function isVerbose() |
|
125 | - { |
|
112 | + public function isVerbose() { |
|
126 | 113 | return $this->output->isVerbose(); |
127 | 114 | } |
128 | 115 | |
129 | 116 | /** |
130 | 117 | * {@inheritdoc} |
131 | 118 | */ |
132 | - public function isVeryVerbose() |
|
133 | - { |
|
119 | + public function isVeryVerbose() { |
|
134 | 120 | return $this->output->isVeryVerbose(); |
135 | 121 | } |
136 | 122 | |
137 | 123 | /** |
138 | 124 | * {@inheritdoc} |
139 | 125 | */ |
140 | - public function isDebug() |
|
141 | - { |
|
126 | + public function isDebug() { |
|
142 | 127 | return $this->output->isDebug(); |
143 | 128 | } |
144 | 129 | |
145 | - protected function getErrorOutput() |
|
146 | - { |
|
130 | + protected function getErrorOutput() { |
|
147 | 131 | if (!$this->output instanceof ConsoleOutputInterface) { |
148 | 132 | return $this->output; |
149 | 133 | } |
@@ -18,41 +18,41 @@ |
||
18 | 18 | */ |
19 | 19 | interface OutputFormatterInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Sets the decorated flag. |
|
23 | - */ |
|
24 | - public function setDecorated(bool $decorated); |
|
25 | - |
|
26 | - /** |
|
27 | - * Gets the decorated flag. |
|
28 | - * |
|
29 | - * @return bool true if the output will decorate messages, false otherwise |
|
30 | - */ |
|
31 | - public function isDecorated(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Sets a new style. |
|
35 | - */ |
|
36 | - public function setStyle(string $name, OutputFormatterStyleInterface $style); |
|
37 | - |
|
38 | - /** |
|
39 | - * Checks if output formatter has style with specified name. |
|
40 | - * |
|
41 | - * @return bool |
|
42 | - */ |
|
43 | - public function hasStyle(string $name); |
|
44 | - |
|
45 | - /** |
|
46 | - * Gets style options from style with specified name. |
|
47 | - * |
|
48 | - * @return OutputFormatterStyleInterface |
|
49 | - * |
|
50 | - * @throws \InvalidArgumentException When style isn't defined |
|
51 | - */ |
|
52 | - public function getStyle(string $name); |
|
53 | - |
|
54 | - /** |
|
55 | - * Formats a message according to the given styles. |
|
56 | - */ |
|
57 | - public function format(?string $message); |
|
21 | + /** |
|
22 | + * Sets the decorated flag. |
|
23 | + */ |
|
24 | + public function setDecorated(bool $decorated); |
|
25 | + |
|
26 | + /** |
|
27 | + * Gets the decorated flag. |
|
28 | + * |
|
29 | + * @return bool true if the output will decorate messages, false otherwise |
|
30 | + */ |
|
31 | + public function isDecorated(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Sets a new style. |
|
35 | + */ |
|
36 | + public function setStyle(string $name, OutputFormatterStyleInterface $style); |
|
37 | + |
|
38 | + /** |
|
39 | + * Checks if output formatter has style with specified name. |
|
40 | + * |
|
41 | + * @return bool |
|
42 | + */ |
|
43 | + public function hasStyle(string $name); |
|
44 | + |
|
45 | + /** |
|
46 | + * Gets style options from style with specified name. |
|
47 | + * |
|
48 | + * @return OutputFormatterStyleInterface |
|
49 | + * |
|
50 | + * @throws \InvalidArgumentException When style isn't defined |
|
51 | + */ |
|
52 | + public function getStyle(string $name); |
|
53 | + |
|
54 | + /** |
|
55 | + * Formats a message according to the given styles. |
|
56 | + */ |
|
57 | + public function format(?string $message); |
|
58 | 58 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Sets the decorated flag. |
23 | 23 | */ |
24 | - public function setDecorated(bool $decorated); |
|
24 | + public function setDecorated( bool $decorated ); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Gets the decorated flag. |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * Sets a new style. |
35 | 35 | */ |
36 | - public function setStyle(string $name, OutputFormatterStyleInterface $style); |
|
36 | + public function setStyle( string $name, OutputFormatterStyleInterface $style ); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Checks if output formatter has style with specified name. |
40 | 40 | * |
41 | 41 | * @return bool |
42 | 42 | */ |
43 | - public function hasStyle(string $name); |
|
43 | + public function hasStyle( string $name ); |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Gets style options from style with specified name. |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @throws \InvalidArgumentException When style isn't defined |
51 | 51 | */ |
52 | - public function getStyle(string $name); |
|
52 | + public function getStyle( string $name ); |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Formats a message according to the given styles. |
56 | 56 | */ |
57 | - public function format(?string $message); |
|
57 | + public function format( ?string $message ); |
|
58 | 58 | } |
@@ -16,8 +16,7 @@ |
||
16 | 16 | * |
17 | 17 | * @author Konstantin Kudryashov <[email protected]> |
18 | 18 | */ |
19 | -interface OutputFormatterInterface |
|
20 | -{ |
|
19 | +interface OutputFormatterInterface { |
|
21 | 20 | /** |
22 | 21 | * Sets the decorated flag. |
23 | 22 | */ |
@@ -19,92 +19,92 @@ |
||
19 | 19 | */ |
20 | 20 | class OutputFormatterStyleStack implements ResetInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * @var OutputFormatterStyleInterface[] |
|
24 | - */ |
|
25 | - private $styles; |
|
26 | - |
|
27 | - private $emptyStyle; |
|
28 | - |
|
29 | - public function __construct(OutputFormatterStyleInterface $emptyStyle = null) |
|
30 | - { |
|
31 | - $this->emptyStyle = $emptyStyle ?? new OutputFormatterStyle(); |
|
32 | - $this->reset(); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Resets stack (ie. empty internal arrays). |
|
37 | - */ |
|
38 | - public function reset() |
|
39 | - { |
|
40 | - $this->styles = []; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Pushes a style in the stack. |
|
45 | - */ |
|
46 | - public function push(OutputFormatterStyleInterface $style) |
|
47 | - { |
|
48 | - $this->styles[] = $style; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Pops a style from the stack. |
|
53 | - * |
|
54 | - * @return OutputFormatterStyleInterface |
|
55 | - * |
|
56 | - * @throws InvalidArgumentException When style tags incorrectly nested |
|
57 | - */ |
|
58 | - public function pop(OutputFormatterStyleInterface $style = null) |
|
59 | - { |
|
60 | - if (empty($this->styles)) { |
|
61 | - return $this->emptyStyle; |
|
62 | - } |
|
63 | - |
|
64 | - if (null === $style) { |
|
65 | - return array_pop($this->styles); |
|
66 | - } |
|
67 | - |
|
68 | - foreach (array_reverse($this->styles, true) as $index => $stackedStyle) { |
|
69 | - if ($style->apply('') === $stackedStyle->apply('')) { |
|
70 | - $this->styles = \array_slice($this->styles, 0, $index); |
|
71 | - |
|
72 | - return $stackedStyle; |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - throw new InvalidArgumentException('Incorrectly nested style tag found.'); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Computes current style with stacks top codes. |
|
81 | - * |
|
82 | - * @return OutputFormatterStyle |
|
83 | - */ |
|
84 | - public function getCurrent() |
|
85 | - { |
|
86 | - if (empty($this->styles)) { |
|
87 | - return $this->emptyStyle; |
|
88 | - } |
|
89 | - |
|
90 | - return $this->styles[\count($this->styles) - 1]; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @return $this |
|
95 | - */ |
|
96 | - public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) |
|
97 | - { |
|
98 | - $this->emptyStyle = $emptyStyle; |
|
99 | - |
|
100 | - return $this; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @return OutputFormatterStyleInterface |
|
105 | - */ |
|
106 | - public function getEmptyStyle() |
|
107 | - { |
|
108 | - return $this->emptyStyle; |
|
109 | - } |
|
22 | + /** |
|
23 | + * @var OutputFormatterStyleInterface[] |
|
24 | + */ |
|
25 | + private $styles; |
|
26 | + |
|
27 | + private $emptyStyle; |
|
28 | + |
|
29 | + public function __construct(OutputFormatterStyleInterface $emptyStyle = null) |
|
30 | + { |
|
31 | + $this->emptyStyle = $emptyStyle ?? new OutputFormatterStyle(); |
|
32 | + $this->reset(); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Resets stack (ie. empty internal arrays). |
|
37 | + */ |
|
38 | + public function reset() |
|
39 | + { |
|
40 | + $this->styles = []; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Pushes a style in the stack. |
|
45 | + */ |
|
46 | + public function push(OutputFormatterStyleInterface $style) |
|
47 | + { |
|
48 | + $this->styles[] = $style; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Pops a style from the stack. |
|
53 | + * |
|
54 | + * @return OutputFormatterStyleInterface |
|
55 | + * |
|
56 | + * @throws InvalidArgumentException When style tags incorrectly nested |
|
57 | + */ |
|
58 | + public function pop(OutputFormatterStyleInterface $style = null) |
|
59 | + { |
|
60 | + if (empty($this->styles)) { |
|
61 | + return $this->emptyStyle; |
|
62 | + } |
|
63 | + |
|
64 | + if (null === $style) { |
|
65 | + return array_pop($this->styles); |
|
66 | + } |
|
67 | + |
|
68 | + foreach (array_reverse($this->styles, true) as $index => $stackedStyle) { |
|
69 | + if ($style->apply('') === $stackedStyle->apply('')) { |
|
70 | + $this->styles = \array_slice($this->styles, 0, $index); |
|
71 | + |
|
72 | + return $stackedStyle; |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + throw new InvalidArgumentException('Incorrectly nested style tag found.'); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Computes current style with stacks top codes. |
|
81 | + * |
|
82 | + * @return OutputFormatterStyle |
|
83 | + */ |
|
84 | + public function getCurrent() |
|
85 | + { |
|
86 | + if (empty($this->styles)) { |
|
87 | + return $this->emptyStyle; |
|
88 | + } |
|
89 | + |
|
90 | + return $this->styles[\count($this->styles) - 1]; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @return $this |
|
95 | + */ |
|
96 | + public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) |
|
97 | + { |
|
98 | + $this->emptyStyle = $emptyStyle; |
|
99 | + |
|
100 | + return $this; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @return OutputFormatterStyleInterface |
|
105 | + */ |
|
106 | + public function getEmptyStyle() |
|
107 | + { |
|
108 | + return $this->emptyStyle; |
|
109 | + } |
|
110 | 110 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | private $emptyStyle; |
28 | 28 | |
29 | - public function __construct(OutputFormatterStyleInterface $emptyStyle = null) |
|
29 | + public function __construct( OutputFormatterStyleInterface $emptyStyle = null ) |
|
30 | 30 | { |
31 | 31 | $this->emptyStyle = $emptyStyle ?? new OutputFormatterStyle(); |
32 | 32 | $this->reset(); |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function reset() |
39 | 39 | { |
40 | - $this->styles = []; |
|
40 | + $this->styles = [ ]; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Pushes a style in the stack. |
45 | 45 | */ |
46 | - public function push(OutputFormatterStyleInterface $style) |
|
46 | + public function push( OutputFormatterStyleInterface $style ) |
|
47 | 47 | { |
48 | - $this->styles[] = $style; |
|
48 | + $this->styles[ ] = $style; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -55,25 +55,25 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @throws InvalidArgumentException When style tags incorrectly nested |
57 | 57 | */ |
58 | - public function pop(OutputFormatterStyleInterface $style = null) |
|
58 | + public function pop( OutputFormatterStyleInterface $style = null ) |
|
59 | 59 | { |
60 | - if (empty($this->styles)) { |
|
60 | + if ( empty( $this->styles ) ) { |
|
61 | 61 | return $this->emptyStyle; |
62 | 62 | } |
63 | 63 | |
64 | - if (null === $style) { |
|
65 | - return array_pop($this->styles); |
|
64 | + if ( null === $style ) { |
|
65 | + return array_pop( $this->styles ); |
|
66 | 66 | } |
67 | 67 | |
68 | - foreach (array_reverse($this->styles, true) as $index => $stackedStyle) { |
|
69 | - if ($style->apply('') === $stackedStyle->apply('')) { |
|
70 | - $this->styles = \array_slice($this->styles, 0, $index); |
|
68 | + foreach ( array_reverse( $this->styles, true ) as $index => $stackedStyle ) { |
|
69 | + if ( $style->apply( '' ) === $stackedStyle->apply( '' ) ) { |
|
70 | + $this->styles = \array_slice( $this->styles, 0, $index ); |
|
71 | 71 | |
72 | 72 | return $stackedStyle; |
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | - throw new InvalidArgumentException('Incorrectly nested style tag found.'); |
|
76 | + throw new InvalidArgumentException( 'Incorrectly nested style tag found.' ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -83,17 +83,17 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function getCurrent() |
85 | 85 | { |
86 | - if (empty($this->styles)) { |
|
86 | + if ( empty( $this->styles ) ) { |
|
87 | 87 | return $this->emptyStyle; |
88 | 88 | } |
89 | 89 | |
90 | - return $this->styles[\count($this->styles) - 1]; |
|
90 | + return $this->styles[ \count( $this->styles ) - 1 ]; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * @return $this |
95 | 95 | */ |
96 | - public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) |
|
96 | + public function setEmptyStyle( OutputFormatterStyleInterface $emptyStyle ) |
|
97 | 97 | { |
98 | 98 | $this->emptyStyle = $emptyStyle; |
99 | 99 |
@@ -17,8 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @author Jean-François Simon <[email protected]> |
19 | 19 | */ |
20 | -class OutputFormatterStyleStack implements ResetInterface |
|
21 | -{ |
|
20 | +class OutputFormatterStyleStack implements ResetInterface { |
|
22 | 21 | /** |
23 | 22 | * @var OutputFormatterStyleInterface[] |
24 | 23 | */ |
@@ -26,8 +25,7 @@ discard block |
||
26 | 25 | |
27 | 26 | private $emptyStyle; |
28 | 27 | |
29 | - public function __construct(OutputFormatterStyleInterface $emptyStyle = null) |
|
30 | - { |
|
28 | + public function __construct(OutputFormatterStyleInterface $emptyStyle = null) { |
|
31 | 29 | $this->emptyStyle = $emptyStyle ?? new OutputFormatterStyle(); |
32 | 30 | $this->reset(); |
33 | 31 | } |
@@ -35,16 +33,14 @@ discard block |
||
35 | 33 | /** |
36 | 34 | * Resets stack (ie. empty internal arrays). |
37 | 35 | */ |
38 | - public function reset() |
|
39 | - { |
|
36 | + public function reset() { |
|
40 | 37 | $this->styles = []; |
41 | 38 | } |
42 | 39 | |
43 | 40 | /** |
44 | 41 | * Pushes a style in the stack. |
45 | 42 | */ |
46 | - public function push(OutputFormatterStyleInterface $style) |
|
47 | - { |
|
43 | + public function push(OutputFormatterStyleInterface $style) { |
|
48 | 44 | $this->styles[] = $style; |
49 | 45 | } |
50 | 46 | |
@@ -55,8 +51,7 @@ discard block |
||
55 | 51 | * |
56 | 52 | * @throws InvalidArgumentException When style tags incorrectly nested |
57 | 53 | */ |
58 | - public function pop(OutputFormatterStyleInterface $style = null) |
|
59 | - { |
|
54 | + public function pop(OutputFormatterStyleInterface $style = null) { |
|
60 | 55 | if (empty($this->styles)) { |
61 | 56 | return $this->emptyStyle; |
62 | 57 | } |
@@ -81,8 +76,7 @@ discard block |
||
81 | 76 | * |
82 | 77 | * @return OutputFormatterStyle |
83 | 78 | */ |
84 | - public function getCurrent() |
|
85 | - { |
|
79 | + public function getCurrent() { |
|
86 | 80 | if (empty($this->styles)) { |
87 | 81 | return $this->emptyStyle; |
88 | 82 | } |
@@ -93,8 +87,7 @@ discard block |
||
93 | 87 | /** |
94 | 88 | * @return $this |
95 | 89 | */ |
96 | - public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) |
|
97 | - { |
|
90 | + public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) { |
|
98 | 91 | $this->emptyStyle = $emptyStyle; |
99 | 92 | |
100 | 93 | return $this; |
@@ -103,8 +96,7 @@ discard block |
||
103 | 96 | /** |
104 | 97 | * @return OutputFormatterStyleInterface |
105 | 98 | */ |
106 | - public function getEmptyStyle() |
|
107 | - { |
|
99 | + public function getEmptyStyle() { |
|
108 | 100 | return $this->emptyStyle; |
109 | 101 | } |
110 | 102 | } |
@@ -15,51 +15,51 @@ |
||
15 | 15 | */ |
16 | 16 | final class NullOutputFormatterStyle implements OutputFormatterStyleInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * {@inheritdoc} |
|
20 | - */ |
|
21 | - public function apply(string $text): string |
|
22 | - { |
|
23 | - return $text; |
|
24 | - } |
|
18 | + /** |
|
19 | + * {@inheritdoc} |
|
20 | + */ |
|
21 | + public function apply(string $text): string |
|
22 | + { |
|
23 | + return $text; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * {@inheritdoc} |
|
28 | - */ |
|
29 | - public function setBackground(string $color = null): void |
|
30 | - { |
|
31 | - // do nothing |
|
32 | - } |
|
26 | + /** |
|
27 | + * {@inheritdoc} |
|
28 | + */ |
|
29 | + public function setBackground(string $color = null): void |
|
30 | + { |
|
31 | + // do nothing |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * {@inheritdoc} |
|
36 | - */ |
|
37 | - public function setForeground(string $color = null): void |
|
38 | - { |
|
39 | - // do nothing |
|
40 | - } |
|
34 | + /** |
|
35 | + * {@inheritdoc} |
|
36 | + */ |
|
37 | + public function setForeground(string $color = null): void |
|
38 | + { |
|
39 | + // do nothing |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * {@inheritdoc} |
|
44 | - */ |
|
45 | - public function setOption(string $option): void |
|
46 | - { |
|
47 | - // do nothing |
|
48 | - } |
|
42 | + /** |
|
43 | + * {@inheritdoc} |
|
44 | + */ |
|
45 | + public function setOption(string $option): void |
|
46 | + { |
|
47 | + // do nothing |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritdoc} |
|
52 | - */ |
|
53 | - public function setOptions(array $options): void |
|
54 | - { |
|
55 | - // do nothing |
|
56 | - } |
|
50 | + /** |
|
51 | + * {@inheritdoc} |
|
52 | + */ |
|
53 | + public function setOptions(array $options): void |
|
54 | + { |
|
55 | + // do nothing |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritdoc} |
|
60 | - */ |
|
61 | - public function unsetOption(string $option): void |
|
62 | - { |
|
63 | - // do nothing |
|
64 | - } |
|
58 | + /** |
|
59 | + * {@inheritdoc} |
|
60 | + */ |
|
61 | + public function unsetOption(string $option): void |
|
62 | + { |
|
63 | + // do nothing |
|
64 | + } |
|
65 | 65 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * {@inheritdoc} |
20 | 20 | */ |
21 | - public function apply(string $text): string |
|
21 | + public function apply( string $text ): string |
|
22 | 22 | { |
23 | 23 | return $text; |
24 | 24 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * {@inheritdoc} |
28 | 28 | */ |
29 | - public function setBackground(string $color = null): void |
|
29 | + public function setBackground( string $color = null ): void |
|
30 | 30 | { |
31 | 31 | // do nothing |
32 | 32 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | /** |
35 | 35 | * {@inheritdoc} |
36 | 36 | */ |
37 | - public function setForeground(string $color = null): void |
|
37 | + public function setForeground( string $color = null ): void |
|
38 | 38 | { |
39 | 39 | // do nothing |
40 | 40 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * {@inheritdoc} |
44 | 44 | */ |
45 | - public function setOption(string $option): void |
|
45 | + public function setOption( string $option ): void |
|
46 | 46 | { |
47 | 47 | // do nothing |
48 | 48 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * {@inheritdoc} |
52 | 52 | */ |
53 | - public function setOptions(array $options): void |
|
53 | + public function setOptions( array $options ): void |
|
54 | 54 | { |
55 | 55 | // do nothing |
56 | 56 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * {@inheritdoc} |
60 | 60 | */ |
61 | - public function unsetOption(string $option): void |
|
61 | + public function unsetOption( string $option ): void |
|
62 | 62 | { |
63 | 63 | // do nothing |
64 | 64 | } |
@@ -13,8 +13,7 @@ |
||
13 | 13 | /** |
14 | 14 | * @author Tien Xuan Vo <[email protected]> |
15 | 15 | */ |
16 | -final class NullOutputFormatterStyle implements OutputFormatterStyleInterface |
|
17 | -{ |
|
16 | +final class NullOutputFormatterStyle implements OutputFormatterStyleInterface { |
|
18 | 17 | /** |
19 | 18 | * {@inheritdoc} |
20 | 19 | */ |
@@ -21,263 +21,263 @@ |
||
21 | 21 | */ |
22 | 22 | class OutputFormatter implements WrappableOutputFormatterInterface |
23 | 23 | { |
24 | - private $decorated; |
|
25 | - private $styles = []; |
|
26 | - private $styleStack; |
|
27 | - |
|
28 | - public function __clone() |
|
29 | - { |
|
30 | - $this->styleStack = clone $this->styleStack; |
|
31 | - foreach ($this->styles as $key => $value) { |
|
32 | - $this->styles[$key] = clone $value; |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Escapes "<" special char in given text. |
|
38 | - * |
|
39 | - * @return string Escaped text |
|
40 | - */ |
|
41 | - public static function escape(string $text) |
|
42 | - { |
|
43 | - $text = preg_replace('/([^\\\\]?)</', '$1\\<', $text); |
|
44 | - |
|
45 | - return self::escapeTrailingBackslash($text); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Escapes trailing "\" in given text. |
|
50 | - * |
|
51 | - * @internal |
|
52 | - */ |
|
53 | - public static function escapeTrailingBackslash(string $text): string |
|
54 | - { |
|
55 | - if (str_ends_with($text, '\\')) { |
|
56 | - $len = \strlen($text); |
|
57 | - $text = rtrim($text, '\\'); |
|
58 | - $text = str_replace("\0", '', $text); |
|
59 | - $text .= str_repeat("\0", $len - \strlen($text)); |
|
60 | - } |
|
61 | - |
|
62 | - return $text; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Initializes console output formatter. |
|
67 | - * |
|
68 | - * @param OutputFormatterStyleInterface[] $styles Array of "name => FormatterStyle" instances |
|
69 | - */ |
|
70 | - public function __construct(bool $decorated = false, array $styles = []) |
|
71 | - { |
|
72 | - $this->decorated = $decorated; |
|
73 | - |
|
74 | - $this->setStyle('error', new OutputFormatterStyle('white', 'red')); |
|
75 | - $this->setStyle('info', new OutputFormatterStyle('green')); |
|
76 | - $this->setStyle('comment', new OutputFormatterStyle('yellow')); |
|
77 | - $this->setStyle('question', new OutputFormatterStyle('black', 'cyan')); |
|
78 | - |
|
79 | - foreach ($styles as $name => $style) { |
|
80 | - $this->setStyle($name, $style); |
|
81 | - } |
|
82 | - |
|
83 | - $this->styleStack = new OutputFormatterStyleStack(); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * {@inheritdoc} |
|
88 | - */ |
|
89 | - public function setDecorated(bool $decorated) |
|
90 | - { |
|
91 | - $this->decorated = $decorated; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * {@inheritdoc} |
|
96 | - */ |
|
97 | - public function isDecorated() |
|
98 | - { |
|
99 | - return $this->decorated; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * {@inheritdoc} |
|
104 | - */ |
|
105 | - public function setStyle(string $name, OutputFormatterStyleInterface $style) |
|
106 | - { |
|
107 | - $this->styles[strtolower($name)] = $style; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * {@inheritdoc} |
|
112 | - */ |
|
113 | - public function hasStyle(string $name) |
|
114 | - { |
|
115 | - return isset($this->styles[strtolower($name)]); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * {@inheritdoc} |
|
120 | - */ |
|
121 | - public function getStyle(string $name) |
|
122 | - { |
|
123 | - if (!$this->hasStyle($name)) { |
|
124 | - throw new InvalidArgumentException(sprintf('Undefined style: "%s".', $name)); |
|
125 | - } |
|
126 | - |
|
127 | - return $this->styles[strtolower($name)]; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * {@inheritdoc} |
|
132 | - */ |
|
133 | - public function format(?string $message) |
|
134 | - { |
|
135 | - return $this->formatAndWrap($message, 0); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * {@inheritdoc} |
|
140 | - */ |
|
141 | - public function formatAndWrap(?string $message, int $width) |
|
142 | - { |
|
143 | - $offset = 0; |
|
144 | - $output = ''; |
|
145 | - $tagRegex = '[a-z][^<>]*+'; |
|
146 | - $currentLineLength = 0; |
|
147 | - preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, \PREG_OFFSET_CAPTURE); |
|
148 | - foreach ($matches[0] as $i => $match) { |
|
149 | - $pos = $match[1]; |
|
150 | - $text = $match[0]; |
|
151 | - |
|
152 | - if (0 != $pos && '\\' == $message[$pos - 1]) { |
|
153 | - continue; |
|
154 | - } |
|
155 | - |
|
156 | - // add the text up to the next tag |
|
157 | - $output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset), $output, $width, $currentLineLength); |
|
158 | - $offset = $pos + \strlen($text); |
|
159 | - |
|
160 | - // opening tag? |
|
161 | - if ($open = '/' != $text[1]) { |
|
162 | - $tag = $matches[1][$i][0]; |
|
163 | - } else { |
|
164 | - $tag = $matches[3][$i][0] ?? ''; |
|
165 | - } |
|
166 | - |
|
167 | - if (!$open && !$tag) { |
|
168 | - // </> |
|
169 | - $this->styleStack->pop(); |
|
170 | - } elseif (null === $style = $this->createStyleFromString($tag)) { |
|
171 | - $output .= $this->applyCurrentStyle($text, $output, $width, $currentLineLength); |
|
172 | - } elseif ($open) { |
|
173 | - $this->styleStack->push($style); |
|
174 | - } else { |
|
175 | - $this->styleStack->pop($style); |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - $output .= $this->applyCurrentStyle(substr($message, $offset), $output, $width, $currentLineLength); |
|
180 | - |
|
181 | - if (str_contains($output, "\0")) { |
|
182 | - return strtr($output, ["\0" => '\\', '\\<' => '<']); |
|
183 | - } |
|
184 | - |
|
185 | - return str_replace('\\<', '<', $output); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @return OutputFormatterStyleStack |
|
190 | - */ |
|
191 | - public function getStyleStack() |
|
192 | - { |
|
193 | - return $this->styleStack; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Tries to create new style instance from string. |
|
198 | - */ |
|
199 | - private function createStyleFromString(string $string): ?OutputFormatterStyleInterface |
|
200 | - { |
|
201 | - if (isset($this->styles[$string])) { |
|
202 | - return $this->styles[$string]; |
|
203 | - } |
|
204 | - |
|
205 | - if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', $string, $matches, \PREG_SET_ORDER)) { |
|
206 | - return null; |
|
207 | - } |
|
208 | - |
|
209 | - $style = new OutputFormatterStyle(); |
|
210 | - foreach ($matches as $match) { |
|
211 | - array_shift($match); |
|
212 | - $match[0] = strtolower($match[0]); |
|
213 | - |
|
214 | - if ('fg' == $match[0]) { |
|
215 | - $style->setForeground(strtolower($match[1])); |
|
216 | - } elseif ('bg' == $match[0]) { |
|
217 | - $style->setBackground(strtolower($match[1])); |
|
218 | - } elseif ('href' === $match[0]) { |
|
219 | - $style->setHref($match[1]); |
|
220 | - } elseif ('options' === $match[0]) { |
|
221 | - preg_match_all('([^,;]+)', strtolower($match[1]), $options); |
|
222 | - $options = array_shift($options); |
|
223 | - foreach ($options as $option) { |
|
224 | - $style->setOption($option); |
|
225 | - } |
|
226 | - } else { |
|
227 | - return null; |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - return $style; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Applies current style from stack to text, if must be applied. |
|
236 | - */ |
|
237 | - private function applyCurrentStyle(string $text, string $current, int $width, int &$currentLineLength): string |
|
238 | - { |
|
239 | - if ('' === $text) { |
|
240 | - return ''; |
|
241 | - } |
|
242 | - |
|
243 | - if (!$width) { |
|
244 | - return $this->isDecorated() ? $this->styleStack->getCurrent()->apply($text) : $text; |
|
245 | - } |
|
246 | - |
|
247 | - if (!$currentLineLength && '' !== $current) { |
|
248 | - $text = ltrim($text); |
|
249 | - } |
|
250 | - |
|
251 | - if ($currentLineLength) { |
|
252 | - $prefix = substr($text, 0, $i = $width - $currentLineLength)."\n"; |
|
253 | - $text = substr($text, $i); |
|
254 | - } else { |
|
255 | - $prefix = ''; |
|
256 | - } |
|
257 | - |
|
258 | - preg_match('~(\\n)$~', $text, $matches); |
|
259 | - $text = $prefix.preg_replace('~([^\\n]{'.$width.'})\\ *~', "\$1\n", $text); |
|
260 | - $text = rtrim($text, "\n").($matches[1] ?? ''); |
|
261 | - |
|
262 | - if (!$currentLineLength && '' !== $current && "\n" !== substr($current, -1)) { |
|
263 | - $text = "\n".$text; |
|
264 | - } |
|
265 | - |
|
266 | - $lines = explode("\n", $text); |
|
267 | - |
|
268 | - foreach ($lines as $line) { |
|
269 | - $currentLineLength += \strlen($line); |
|
270 | - if ($width <= $currentLineLength) { |
|
271 | - $currentLineLength = 0; |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - if ($this->isDecorated()) { |
|
276 | - foreach ($lines as $i => $line) { |
|
277 | - $lines[$i] = $this->styleStack->getCurrent()->apply($line); |
|
278 | - } |
|
279 | - } |
|
280 | - |
|
281 | - return implode("\n", $lines); |
|
282 | - } |
|
24 | + private $decorated; |
|
25 | + private $styles = []; |
|
26 | + private $styleStack; |
|
27 | + |
|
28 | + public function __clone() |
|
29 | + { |
|
30 | + $this->styleStack = clone $this->styleStack; |
|
31 | + foreach ($this->styles as $key => $value) { |
|
32 | + $this->styles[$key] = clone $value; |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Escapes "<" special char in given text. |
|
38 | + * |
|
39 | + * @return string Escaped text |
|
40 | + */ |
|
41 | + public static function escape(string $text) |
|
42 | + { |
|
43 | + $text = preg_replace('/([^\\\\]?)</', '$1\\<', $text); |
|
44 | + |
|
45 | + return self::escapeTrailingBackslash($text); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Escapes trailing "\" in given text. |
|
50 | + * |
|
51 | + * @internal |
|
52 | + */ |
|
53 | + public static function escapeTrailingBackslash(string $text): string |
|
54 | + { |
|
55 | + if (str_ends_with($text, '\\')) { |
|
56 | + $len = \strlen($text); |
|
57 | + $text = rtrim($text, '\\'); |
|
58 | + $text = str_replace("\0", '', $text); |
|
59 | + $text .= str_repeat("\0", $len - \strlen($text)); |
|
60 | + } |
|
61 | + |
|
62 | + return $text; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Initializes console output formatter. |
|
67 | + * |
|
68 | + * @param OutputFormatterStyleInterface[] $styles Array of "name => FormatterStyle" instances |
|
69 | + */ |
|
70 | + public function __construct(bool $decorated = false, array $styles = []) |
|
71 | + { |
|
72 | + $this->decorated = $decorated; |
|
73 | + |
|
74 | + $this->setStyle('error', new OutputFormatterStyle('white', 'red')); |
|
75 | + $this->setStyle('info', new OutputFormatterStyle('green')); |
|
76 | + $this->setStyle('comment', new OutputFormatterStyle('yellow')); |
|
77 | + $this->setStyle('question', new OutputFormatterStyle('black', 'cyan')); |
|
78 | + |
|
79 | + foreach ($styles as $name => $style) { |
|
80 | + $this->setStyle($name, $style); |
|
81 | + } |
|
82 | + |
|
83 | + $this->styleStack = new OutputFormatterStyleStack(); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * {@inheritdoc} |
|
88 | + */ |
|
89 | + public function setDecorated(bool $decorated) |
|
90 | + { |
|
91 | + $this->decorated = $decorated; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * {@inheritdoc} |
|
96 | + */ |
|
97 | + public function isDecorated() |
|
98 | + { |
|
99 | + return $this->decorated; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * {@inheritdoc} |
|
104 | + */ |
|
105 | + public function setStyle(string $name, OutputFormatterStyleInterface $style) |
|
106 | + { |
|
107 | + $this->styles[strtolower($name)] = $style; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * {@inheritdoc} |
|
112 | + */ |
|
113 | + public function hasStyle(string $name) |
|
114 | + { |
|
115 | + return isset($this->styles[strtolower($name)]); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * {@inheritdoc} |
|
120 | + */ |
|
121 | + public function getStyle(string $name) |
|
122 | + { |
|
123 | + if (!$this->hasStyle($name)) { |
|
124 | + throw new InvalidArgumentException(sprintf('Undefined style: "%s".', $name)); |
|
125 | + } |
|
126 | + |
|
127 | + return $this->styles[strtolower($name)]; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * {@inheritdoc} |
|
132 | + */ |
|
133 | + public function format(?string $message) |
|
134 | + { |
|
135 | + return $this->formatAndWrap($message, 0); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * {@inheritdoc} |
|
140 | + */ |
|
141 | + public function formatAndWrap(?string $message, int $width) |
|
142 | + { |
|
143 | + $offset = 0; |
|
144 | + $output = ''; |
|
145 | + $tagRegex = '[a-z][^<>]*+'; |
|
146 | + $currentLineLength = 0; |
|
147 | + preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, \PREG_OFFSET_CAPTURE); |
|
148 | + foreach ($matches[0] as $i => $match) { |
|
149 | + $pos = $match[1]; |
|
150 | + $text = $match[0]; |
|
151 | + |
|
152 | + if (0 != $pos && '\\' == $message[$pos - 1]) { |
|
153 | + continue; |
|
154 | + } |
|
155 | + |
|
156 | + // add the text up to the next tag |
|
157 | + $output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset), $output, $width, $currentLineLength); |
|
158 | + $offset = $pos + \strlen($text); |
|
159 | + |
|
160 | + // opening tag? |
|
161 | + if ($open = '/' != $text[1]) { |
|
162 | + $tag = $matches[1][$i][0]; |
|
163 | + } else { |
|
164 | + $tag = $matches[3][$i][0] ?? ''; |
|
165 | + } |
|
166 | + |
|
167 | + if (!$open && !$tag) { |
|
168 | + // </> |
|
169 | + $this->styleStack->pop(); |
|
170 | + } elseif (null === $style = $this->createStyleFromString($tag)) { |
|
171 | + $output .= $this->applyCurrentStyle($text, $output, $width, $currentLineLength); |
|
172 | + } elseif ($open) { |
|
173 | + $this->styleStack->push($style); |
|
174 | + } else { |
|
175 | + $this->styleStack->pop($style); |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + $output .= $this->applyCurrentStyle(substr($message, $offset), $output, $width, $currentLineLength); |
|
180 | + |
|
181 | + if (str_contains($output, "\0")) { |
|
182 | + return strtr($output, ["\0" => '\\', '\\<' => '<']); |
|
183 | + } |
|
184 | + |
|
185 | + return str_replace('\\<', '<', $output); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @return OutputFormatterStyleStack |
|
190 | + */ |
|
191 | + public function getStyleStack() |
|
192 | + { |
|
193 | + return $this->styleStack; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Tries to create new style instance from string. |
|
198 | + */ |
|
199 | + private function createStyleFromString(string $string): ?OutputFormatterStyleInterface |
|
200 | + { |
|
201 | + if (isset($this->styles[$string])) { |
|
202 | + return $this->styles[$string]; |
|
203 | + } |
|
204 | + |
|
205 | + if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', $string, $matches, \PREG_SET_ORDER)) { |
|
206 | + return null; |
|
207 | + } |
|
208 | + |
|
209 | + $style = new OutputFormatterStyle(); |
|
210 | + foreach ($matches as $match) { |
|
211 | + array_shift($match); |
|
212 | + $match[0] = strtolower($match[0]); |
|
213 | + |
|
214 | + if ('fg' == $match[0]) { |
|
215 | + $style->setForeground(strtolower($match[1])); |
|
216 | + } elseif ('bg' == $match[0]) { |
|
217 | + $style->setBackground(strtolower($match[1])); |
|
218 | + } elseif ('href' === $match[0]) { |
|
219 | + $style->setHref($match[1]); |
|
220 | + } elseif ('options' === $match[0]) { |
|
221 | + preg_match_all('([^,;]+)', strtolower($match[1]), $options); |
|
222 | + $options = array_shift($options); |
|
223 | + foreach ($options as $option) { |
|
224 | + $style->setOption($option); |
|
225 | + } |
|
226 | + } else { |
|
227 | + return null; |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + return $style; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Applies current style from stack to text, if must be applied. |
|
236 | + */ |
|
237 | + private function applyCurrentStyle(string $text, string $current, int $width, int &$currentLineLength): string |
|
238 | + { |
|
239 | + if ('' === $text) { |
|
240 | + return ''; |
|
241 | + } |
|
242 | + |
|
243 | + if (!$width) { |
|
244 | + return $this->isDecorated() ? $this->styleStack->getCurrent()->apply($text) : $text; |
|
245 | + } |
|
246 | + |
|
247 | + if (!$currentLineLength && '' !== $current) { |
|
248 | + $text = ltrim($text); |
|
249 | + } |
|
250 | + |
|
251 | + if ($currentLineLength) { |
|
252 | + $prefix = substr($text, 0, $i = $width - $currentLineLength)."\n"; |
|
253 | + $text = substr($text, $i); |
|
254 | + } else { |
|
255 | + $prefix = ''; |
|
256 | + } |
|
257 | + |
|
258 | + preg_match('~(\\n)$~', $text, $matches); |
|
259 | + $text = $prefix.preg_replace('~([^\\n]{'.$width.'})\\ *~', "\$1\n", $text); |
|
260 | + $text = rtrim($text, "\n").($matches[1] ?? ''); |
|
261 | + |
|
262 | + if (!$currentLineLength && '' !== $current && "\n" !== substr($current, -1)) { |
|
263 | + $text = "\n".$text; |
|
264 | + } |
|
265 | + |
|
266 | + $lines = explode("\n", $text); |
|
267 | + |
|
268 | + foreach ($lines as $line) { |
|
269 | + $currentLineLength += \strlen($line); |
|
270 | + if ($width <= $currentLineLength) { |
|
271 | + $currentLineLength = 0; |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + if ($this->isDecorated()) { |
|
276 | + foreach ($lines as $i => $line) { |
|
277 | + $lines[$i] = $this->styleStack->getCurrent()->apply($line); |
|
278 | + } |
|
279 | + } |
|
280 | + |
|
281 | + return implode("\n", $lines); |
|
282 | + } |
|
283 | 283 | } |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | class OutputFormatter implements WrappableOutputFormatterInterface |
23 | 23 | { |
24 | 24 | private $decorated; |
25 | - private $styles = []; |
|
25 | + private $styles = [ ]; |
|
26 | 26 | private $styleStack; |
27 | 27 | |
28 | 28 | public function __clone() |
29 | 29 | { |
30 | 30 | $this->styleStack = clone $this->styleStack; |
31 | - foreach ($this->styles as $key => $value) { |
|
32 | - $this->styles[$key] = clone $value; |
|
31 | + foreach ( $this->styles as $key => $value ) { |
|
32 | + $this->styles[ $key ] = clone $value; |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return string Escaped text |
40 | 40 | */ |
41 | - public static function escape(string $text) |
|
41 | + public static function escape( string $text ) |
|
42 | 42 | { |
43 | - $text = preg_replace('/([^\\\\]?)</', '$1\\<', $text); |
|
43 | + $text = preg_replace( '/([^\\\\]?)</', '$1\\<', $text ); |
|
44 | 44 | |
45 | - return self::escapeTrailingBackslash($text); |
|
45 | + return self::escapeTrailingBackslash( $text ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @internal |
52 | 52 | */ |
53 | - public static function escapeTrailingBackslash(string $text): string |
|
53 | + public static function escapeTrailingBackslash( string $text ): string |
|
54 | 54 | { |
55 | - if (str_ends_with($text, '\\')) { |
|
56 | - $len = \strlen($text); |
|
57 | - $text = rtrim($text, '\\'); |
|
58 | - $text = str_replace("\0", '', $text); |
|
59 | - $text .= str_repeat("\0", $len - \strlen($text)); |
|
55 | + if ( str_ends_with( $text, '\\' ) ) { |
|
56 | + $len = \strlen( $text ); |
|
57 | + $text = rtrim( $text, '\\' ); |
|
58 | + $text = str_replace( "\0", '', $text ); |
|
59 | + $text .= str_repeat( "\0", $len - \strlen( $text ) ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | return $text; |
@@ -67,17 +67,17 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @param OutputFormatterStyleInterface[] $styles Array of "name => FormatterStyle" instances |
69 | 69 | */ |
70 | - public function __construct(bool $decorated = false, array $styles = []) |
|
70 | + public function __construct( bool $decorated = false, array $styles = [ ] ) |
|
71 | 71 | { |
72 | 72 | $this->decorated = $decorated; |
73 | 73 | |
74 | - $this->setStyle('error', new OutputFormatterStyle('white', 'red')); |
|
75 | - $this->setStyle('info', new OutputFormatterStyle('green')); |
|
76 | - $this->setStyle('comment', new OutputFormatterStyle('yellow')); |
|
77 | - $this->setStyle('question', new OutputFormatterStyle('black', 'cyan')); |
|
74 | + $this->setStyle( 'error', new OutputFormatterStyle( 'white', 'red' ) ); |
|
75 | + $this->setStyle( 'info', new OutputFormatterStyle( 'green' ) ); |
|
76 | + $this->setStyle( 'comment', new OutputFormatterStyle( 'yellow' ) ); |
|
77 | + $this->setStyle( 'question', new OutputFormatterStyle( 'black', 'cyan' ) ); |
|
78 | 78 | |
79 | - foreach ($styles as $name => $style) { |
|
80 | - $this->setStyle($name, $style); |
|
79 | + foreach ( $styles as $name => $style ) { |
|
80 | + $this->setStyle( $name, $style ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $this->styleStack = new OutputFormatterStyleStack(); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | /** |
87 | 87 | * {@inheritdoc} |
88 | 88 | */ |
89 | - public function setDecorated(bool $decorated) |
|
89 | + public function setDecorated( bool $decorated ) |
|
90 | 90 | { |
91 | 91 | $this->decorated = $decorated; |
92 | 92 | } |
@@ -102,87 +102,87 @@ discard block |
||
102 | 102 | /** |
103 | 103 | * {@inheritdoc} |
104 | 104 | */ |
105 | - public function setStyle(string $name, OutputFormatterStyleInterface $style) |
|
105 | + public function setStyle( string $name, OutputFormatterStyleInterface $style ) |
|
106 | 106 | { |
107 | - $this->styles[strtolower($name)] = $style; |
|
107 | + $this->styles[ strtolower( $name ) ] = $style; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * {@inheritdoc} |
112 | 112 | */ |
113 | - public function hasStyle(string $name) |
|
113 | + public function hasStyle( string $name ) |
|
114 | 114 | { |
115 | - return isset($this->styles[strtolower($name)]); |
|
115 | + return isset( $this->styles[ strtolower( $name ) ] ); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
119 | 119 | * {@inheritdoc} |
120 | 120 | */ |
121 | - public function getStyle(string $name) |
|
121 | + public function getStyle( string $name ) |
|
122 | 122 | { |
123 | - if (!$this->hasStyle($name)) { |
|
124 | - throw new InvalidArgumentException(sprintf('Undefined style: "%s".', $name)); |
|
123 | + if ( ! $this->hasStyle( $name ) ) { |
|
124 | + throw new InvalidArgumentException( sprintf( 'Undefined style: "%s".', $name ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | - return $this->styles[strtolower($name)]; |
|
127 | + return $this->styles[ strtolower( $name ) ]; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
131 | 131 | * {@inheritdoc} |
132 | 132 | */ |
133 | - public function format(?string $message) |
|
133 | + public function format( ?string $message ) |
|
134 | 134 | { |
135 | - return $this->formatAndWrap($message, 0); |
|
135 | + return $this->formatAndWrap( $message, 0 ); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * {@inheritdoc} |
140 | 140 | */ |
141 | - public function formatAndWrap(?string $message, int $width) |
|
141 | + public function formatAndWrap( ?string $message, int $width ) |
|
142 | 142 | { |
143 | 143 | $offset = 0; |
144 | 144 | $output = ''; |
145 | 145 | $tagRegex = '[a-z][^<>]*+'; |
146 | 146 | $currentLineLength = 0; |
147 | - preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, \PREG_OFFSET_CAPTURE); |
|
148 | - foreach ($matches[0] as $i => $match) { |
|
149 | - $pos = $match[1]; |
|
150 | - $text = $match[0]; |
|
147 | + preg_match_all( "#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, \PREG_OFFSET_CAPTURE ); |
|
148 | + foreach ( $matches[ 0 ] as $i => $match ) { |
|
149 | + $pos = $match[ 1 ]; |
|
150 | + $text = $match[ 0 ]; |
|
151 | 151 | |
152 | - if (0 != $pos && '\\' == $message[$pos - 1]) { |
|
152 | + if ( 0 != $pos && '\\' == $message[ $pos - 1 ] ) { |
|
153 | 153 | continue; |
154 | 154 | } |
155 | 155 | |
156 | 156 | // add the text up to the next tag |
157 | - $output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset), $output, $width, $currentLineLength); |
|
158 | - $offset = $pos + \strlen($text); |
|
157 | + $output .= $this->applyCurrentStyle( substr( $message, $offset, $pos - $offset ), $output, $width, $currentLineLength ); |
|
158 | + $offset = $pos + \strlen( $text ); |
|
159 | 159 | |
160 | 160 | // opening tag? |
161 | - if ($open = '/' != $text[1]) { |
|
162 | - $tag = $matches[1][$i][0]; |
|
161 | + if ( $open = '/' != $text[ 1 ] ) { |
|
162 | + $tag = $matches[ 1 ][ $i ][ 0 ]; |
|
163 | 163 | } else { |
164 | - $tag = $matches[3][$i][0] ?? ''; |
|
164 | + $tag = $matches[ 3 ][ $i ][ 0 ] ?? ''; |
|
165 | 165 | } |
166 | 166 | |
167 | - if (!$open && !$tag) { |
|
167 | + if ( ! $open && ! $tag ) { |
|
168 | 168 | // </> |
169 | 169 | $this->styleStack->pop(); |
170 | - } elseif (null === $style = $this->createStyleFromString($tag)) { |
|
171 | - $output .= $this->applyCurrentStyle($text, $output, $width, $currentLineLength); |
|
172 | - } elseif ($open) { |
|
173 | - $this->styleStack->push($style); |
|
170 | + } elseif ( null === $style = $this->createStyleFromString( $tag ) ) { |
|
171 | + $output .= $this->applyCurrentStyle( $text, $output, $width, $currentLineLength ); |
|
172 | + } elseif ( $open ) { |
|
173 | + $this->styleStack->push( $style ); |
|
174 | 174 | } else { |
175 | - $this->styleStack->pop($style); |
|
175 | + $this->styleStack->pop( $style ); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - $output .= $this->applyCurrentStyle(substr($message, $offset), $output, $width, $currentLineLength); |
|
179 | + $output .= $this->applyCurrentStyle( substr( $message, $offset ), $output, $width, $currentLineLength ); |
|
180 | 180 | |
181 | - if (str_contains($output, "\0")) { |
|
182 | - return strtr($output, ["\0" => '\\', '\\<' => '<']); |
|
181 | + if ( str_contains( $output, "\0" ) ) { |
|
182 | + return strtr( $output, [ "\0" => '\\', '\\<' => '<' ] ); |
|
183 | 183 | } |
184 | 184 | |
185 | - return str_replace('\\<', '<', $output); |
|
185 | + return str_replace( '\\<', '<', $output ); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -196,32 +196,32 @@ discard block |
||
196 | 196 | /** |
197 | 197 | * Tries to create new style instance from string. |
198 | 198 | */ |
199 | - private function createStyleFromString(string $string): ?OutputFormatterStyleInterface |
|
199 | + private function createStyleFromString( string $string ): ?OutputFormatterStyleInterface |
|
200 | 200 | { |
201 | - if (isset($this->styles[$string])) { |
|
202 | - return $this->styles[$string]; |
|
201 | + if ( isset( $this->styles[ $string ] ) ) { |
|
202 | + return $this->styles[ $string ]; |
|
203 | 203 | } |
204 | 204 | |
205 | - if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', $string, $matches, \PREG_SET_ORDER)) { |
|
205 | + if ( ! preg_match_all( '/([^=]+)=([^;]+)(;|$)/', $string, $matches, \PREG_SET_ORDER ) ) { |
|
206 | 206 | return null; |
207 | 207 | } |
208 | 208 | |
209 | 209 | $style = new OutputFormatterStyle(); |
210 | - foreach ($matches as $match) { |
|
211 | - array_shift($match); |
|
212 | - $match[0] = strtolower($match[0]); |
|
213 | - |
|
214 | - if ('fg' == $match[0]) { |
|
215 | - $style->setForeground(strtolower($match[1])); |
|
216 | - } elseif ('bg' == $match[0]) { |
|
217 | - $style->setBackground(strtolower($match[1])); |
|
218 | - } elseif ('href' === $match[0]) { |
|
219 | - $style->setHref($match[1]); |
|
220 | - } elseif ('options' === $match[0]) { |
|
221 | - preg_match_all('([^,;]+)', strtolower($match[1]), $options); |
|
222 | - $options = array_shift($options); |
|
223 | - foreach ($options as $option) { |
|
224 | - $style->setOption($option); |
|
210 | + foreach ( $matches as $match ) { |
|
211 | + array_shift( $match ); |
|
212 | + $match[ 0 ] = strtolower( $match[ 0 ] ); |
|
213 | + |
|
214 | + if ( 'fg' == $match[ 0 ] ) { |
|
215 | + $style->setForeground( strtolower( $match[ 1 ] ) ); |
|
216 | + } elseif ( 'bg' == $match[ 0 ] ) { |
|
217 | + $style->setBackground( strtolower( $match[ 1 ] ) ); |
|
218 | + } elseif ( 'href' === $match[ 0 ] ) { |
|
219 | + $style->setHref( $match[ 1 ] ); |
|
220 | + } elseif ( 'options' === $match[ 0 ] ) { |
|
221 | + preg_match_all( '([^,;]+)', strtolower( $match[ 1 ] ), $options ); |
|
222 | + $options = array_shift( $options ); |
|
223 | + foreach ( $options as $option ) { |
|
224 | + $style->setOption( $option ); |
|
225 | 225 | } |
226 | 226 | } else { |
227 | 227 | return null; |
@@ -234,50 +234,50 @@ discard block |
||
234 | 234 | /** |
235 | 235 | * Applies current style from stack to text, if must be applied. |
236 | 236 | */ |
237 | - private function applyCurrentStyle(string $text, string $current, int $width, int &$currentLineLength): string |
|
237 | + private function applyCurrentStyle( string $text, string $current, int $width, int &$currentLineLength ): string |
|
238 | 238 | { |
239 | - if ('' === $text) { |
|
239 | + if ( '' === $text ) { |
|
240 | 240 | return ''; |
241 | 241 | } |
242 | 242 | |
243 | - if (!$width) { |
|
244 | - return $this->isDecorated() ? $this->styleStack->getCurrent()->apply($text) : $text; |
|
243 | + if ( ! $width ) { |
|
244 | + return $this->isDecorated() ? $this->styleStack->getCurrent()->apply( $text ) : $text; |
|
245 | 245 | } |
246 | 246 | |
247 | - if (!$currentLineLength && '' !== $current) { |
|
248 | - $text = ltrim($text); |
|
247 | + if ( ! $currentLineLength && '' !== $current ) { |
|
248 | + $text = ltrim( $text ); |
|
249 | 249 | } |
250 | 250 | |
251 | - if ($currentLineLength) { |
|
252 | - $prefix = substr($text, 0, $i = $width - $currentLineLength)."\n"; |
|
253 | - $text = substr($text, $i); |
|
251 | + if ( $currentLineLength ) { |
|
252 | + $prefix = substr( $text, 0, $i = $width - $currentLineLength ) . "\n"; |
|
253 | + $text = substr( $text, $i ); |
|
254 | 254 | } else { |
255 | 255 | $prefix = ''; |
256 | 256 | } |
257 | 257 | |
258 | - preg_match('~(\\n)$~', $text, $matches); |
|
259 | - $text = $prefix.preg_replace('~([^\\n]{'.$width.'})\\ *~', "\$1\n", $text); |
|
260 | - $text = rtrim($text, "\n").($matches[1] ?? ''); |
|
258 | + preg_match( '~(\\n)$~', $text, $matches ); |
|
259 | + $text = $prefix . preg_replace( '~([^\\n]{' . $width . '})\\ *~', "\$1\n", $text ); |
|
260 | + $text = rtrim( $text, "\n" ) . ( $matches[ 1 ] ?? '' ); |
|
261 | 261 | |
262 | - if (!$currentLineLength && '' !== $current && "\n" !== substr($current, -1)) { |
|
263 | - $text = "\n".$text; |
|
262 | + if ( ! $currentLineLength && '' !== $current && "\n" !== substr( $current, -1 ) ) { |
|
263 | + $text = "\n" . $text; |
|
264 | 264 | } |
265 | 265 | |
266 | - $lines = explode("\n", $text); |
|
266 | + $lines = explode( "\n", $text ); |
|
267 | 267 | |
268 | - foreach ($lines as $line) { |
|
269 | - $currentLineLength += \strlen($line); |
|
270 | - if ($width <= $currentLineLength) { |
|
268 | + foreach ( $lines as $line ) { |
|
269 | + $currentLineLength += \strlen( $line ); |
|
270 | + if ( $width <= $currentLineLength ) { |
|
271 | 271 | $currentLineLength = 0; |
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
275 | - if ($this->isDecorated()) { |
|
276 | - foreach ($lines as $i => $line) { |
|
277 | - $lines[$i] = $this->styleStack->getCurrent()->apply($line); |
|
275 | + if ( $this->isDecorated() ) { |
|
276 | + foreach ( $lines as $i => $line ) { |
|
277 | + $lines[ $i ] = $this->styleStack->getCurrent()->apply( $line ); |
|
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - return implode("\n", $lines); |
|
281 | + return implode( "\n", $lines ); |
|
282 | 282 | } |
283 | 283 | } |
@@ -19,14 +19,12 @@ discard block |
||
19 | 19 | * @author Konstantin Kudryashov <[email protected]> |
20 | 20 | * @author Roland Franssen <[email protected]> |
21 | 21 | */ |
22 | -class OutputFormatter implements WrappableOutputFormatterInterface |
|
23 | -{ |
|
22 | +class OutputFormatter implements WrappableOutputFormatterInterface { |
|
24 | 23 | private $decorated; |
25 | 24 | private $styles = []; |
26 | 25 | private $styleStack; |
27 | 26 | |
28 | - public function __clone() |
|
29 | - { |
|
27 | + public function __clone() { |
|
30 | 28 | $this->styleStack = clone $this->styleStack; |
31 | 29 | foreach ($this->styles as $key => $value) { |
32 | 30 | $this->styles[$key] = clone $value; |
@@ -38,8 +36,7 @@ discard block |
||
38 | 36 | * |
39 | 37 | * @return string Escaped text |
40 | 38 | */ |
41 | - public static function escape(string $text) |
|
42 | - { |
|
39 | + public static function escape(string $text) { |
|
43 | 40 | $text = preg_replace('/([^\\\\]?)</', '$1\\<', $text); |
44 | 41 | |
45 | 42 | return self::escapeTrailingBackslash($text); |
@@ -67,8 +64,7 @@ discard block |
||
67 | 64 | * |
68 | 65 | * @param OutputFormatterStyleInterface[] $styles Array of "name => FormatterStyle" instances |
69 | 66 | */ |
70 | - public function __construct(bool $decorated = false, array $styles = []) |
|
71 | - { |
|
67 | + public function __construct(bool $decorated = false, array $styles = []) { |
|
72 | 68 | $this->decorated = $decorated; |
73 | 69 | |
74 | 70 | $this->setStyle('error', new OutputFormatterStyle('white', 'red')); |
@@ -86,40 +82,35 @@ discard block |
||
86 | 82 | /** |
87 | 83 | * {@inheritdoc} |
88 | 84 | */ |
89 | - public function setDecorated(bool $decorated) |
|
90 | - { |
|
85 | + public function setDecorated(bool $decorated) { |
|
91 | 86 | $this->decorated = $decorated; |
92 | 87 | } |
93 | 88 | |
94 | 89 | /** |
95 | 90 | * {@inheritdoc} |
96 | 91 | */ |
97 | - public function isDecorated() |
|
98 | - { |
|
92 | + public function isDecorated() { |
|
99 | 93 | return $this->decorated; |
100 | 94 | } |
101 | 95 | |
102 | 96 | /** |
103 | 97 | * {@inheritdoc} |
104 | 98 | */ |
105 | - public function setStyle(string $name, OutputFormatterStyleInterface $style) |
|
106 | - { |
|
99 | + public function setStyle(string $name, OutputFormatterStyleInterface $style) { |
|
107 | 100 | $this->styles[strtolower($name)] = $style; |
108 | 101 | } |
109 | 102 | |
110 | 103 | /** |
111 | 104 | * {@inheritdoc} |
112 | 105 | */ |
113 | - public function hasStyle(string $name) |
|
114 | - { |
|
106 | + public function hasStyle(string $name) { |
|
115 | 107 | return isset($this->styles[strtolower($name)]); |
116 | 108 | } |
117 | 109 | |
118 | 110 | /** |
119 | 111 | * {@inheritdoc} |
120 | 112 | */ |
121 | - public function getStyle(string $name) |
|
122 | - { |
|
113 | + public function getStyle(string $name) { |
|
123 | 114 | if (!$this->hasStyle($name)) { |
124 | 115 | throw new InvalidArgumentException(sprintf('Undefined style: "%s".', $name)); |
125 | 116 | } |
@@ -130,16 +121,14 @@ discard block |
||
130 | 121 | /** |
131 | 122 | * {@inheritdoc} |
132 | 123 | */ |
133 | - public function format(?string $message) |
|
134 | - { |
|
124 | + public function format(?string $message) { |
|
135 | 125 | return $this->formatAndWrap($message, 0); |
136 | 126 | } |
137 | 127 | |
138 | 128 | /** |
139 | 129 | * {@inheritdoc} |
140 | 130 | */ |
141 | - public function formatAndWrap(?string $message, int $width) |
|
142 | - { |
|
131 | + public function formatAndWrap(?string $message, int $width) { |
|
143 | 132 | $offset = 0; |
144 | 133 | $output = ''; |
145 | 134 | $tagRegex = '[a-z][^<>]*+'; |
@@ -188,8 +177,7 @@ discard block |
||
188 | 177 | /** |
189 | 178 | * @return OutputFormatterStyleStack |
190 | 179 | */ |
191 | - public function getStyleStack() |
|
192 | - { |
|
180 | + public function getStyleStack() { |
|
193 | 181 | return $this->styleStack; |
194 | 182 | } |
195 | 183 |
@@ -20,89 +20,89 @@ |
||
20 | 20 | */ |
21 | 21 | class OutputFormatterStyle implements OutputFormatterStyleInterface |
22 | 22 | { |
23 | - private $color; |
|
24 | - private $foreground; |
|
25 | - private $background; |
|
26 | - private $options; |
|
27 | - private $href; |
|
28 | - private $handlesHrefGracefully; |
|
23 | + private $color; |
|
24 | + private $foreground; |
|
25 | + private $background; |
|
26 | + private $options; |
|
27 | + private $href; |
|
28 | + private $handlesHrefGracefully; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Initializes output formatter style. |
|
32 | - * |
|
33 | - * @param string|null $foreground The style foreground color name |
|
34 | - * @param string|null $background The style background color name |
|
35 | - */ |
|
36 | - public function __construct(string $foreground = null, string $background = null, array $options = []) |
|
37 | - { |
|
38 | - $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options); |
|
39 | - } |
|
30 | + /** |
|
31 | + * Initializes output formatter style. |
|
32 | + * |
|
33 | + * @param string|null $foreground The style foreground color name |
|
34 | + * @param string|null $background The style background color name |
|
35 | + */ |
|
36 | + public function __construct(string $foreground = null, string $background = null, array $options = []) |
|
37 | + { |
|
38 | + $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * {@inheritdoc} |
|
43 | - */ |
|
44 | - public function setForeground(string $color = null) |
|
45 | - { |
|
46 | - $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); |
|
47 | - } |
|
41 | + /** |
|
42 | + * {@inheritdoc} |
|
43 | + */ |
|
44 | + public function setForeground(string $color = null) |
|
45 | + { |
|
46 | + $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function setBackground(string $color = null) |
|
53 | - { |
|
54 | - $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); |
|
55 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function setBackground(string $color = null) |
|
53 | + { |
|
54 | + $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); |
|
55 | + } |
|
56 | 56 | |
57 | - public function setHref(string $url): void |
|
58 | - { |
|
59 | - $this->href = $url; |
|
60 | - } |
|
57 | + public function setHref(string $url): void |
|
58 | + { |
|
59 | + $this->href = $url; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * {@inheritdoc} |
|
64 | - */ |
|
65 | - public function setOption(string $option) |
|
66 | - { |
|
67 | - $this->options[] = $option; |
|
68 | - $this->color = new Color($this->foreground, $this->background, $this->options); |
|
69 | - } |
|
62 | + /** |
|
63 | + * {@inheritdoc} |
|
64 | + */ |
|
65 | + public function setOption(string $option) |
|
66 | + { |
|
67 | + $this->options[] = $option; |
|
68 | + $this->color = new Color($this->foreground, $this->background, $this->options); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * {@inheritdoc} |
|
73 | - */ |
|
74 | - public function unsetOption(string $option) |
|
75 | - { |
|
76 | - $pos = array_search($option, $this->options); |
|
77 | - if (false !== $pos) { |
|
78 | - unset($this->options[$pos]); |
|
79 | - } |
|
71 | + /** |
|
72 | + * {@inheritdoc} |
|
73 | + */ |
|
74 | + public function unsetOption(string $option) |
|
75 | + { |
|
76 | + $pos = array_search($option, $this->options); |
|
77 | + if (false !== $pos) { |
|
78 | + unset($this->options[$pos]); |
|
79 | + } |
|
80 | 80 | |
81 | - $this->color = new Color($this->foreground, $this->background, $this->options); |
|
82 | - } |
|
81 | + $this->color = new Color($this->foreground, $this->background, $this->options); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * {@inheritdoc} |
|
86 | - */ |
|
87 | - public function setOptions(array $options) |
|
88 | - { |
|
89 | - $this->color = new Color($this->foreground, $this->background, $this->options = $options); |
|
90 | - } |
|
84 | + /** |
|
85 | + * {@inheritdoc} |
|
86 | + */ |
|
87 | + public function setOptions(array $options) |
|
88 | + { |
|
89 | + $this->color = new Color($this->foreground, $this->background, $this->options = $options); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * {@inheritdoc} |
|
94 | - */ |
|
95 | - public function apply(string $text) |
|
96 | - { |
|
97 | - if (null === $this->handlesHrefGracefully) { |
|
98 | - $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') |
|
99 | - && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100); |
|
100 | - } |
|
92 | + /** |
|
93 | + * {@inheritdoc} |
|
94 | + */ |
|
95 | + public function apply(string $text) |
|
96 | + { |
|
97 | + if (null === $this->handlesHrefGracefully) { |
|
98 | + $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') |
|
99 | + && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100); |
|
100 | + } |
|
101 | 101 | |
102 | - if (null !== $this->href && $this->handlesHrefGracefully) { |
|
103 | - $text = "\033]8;;$this->href\033\\$text\033]8;;\033\\"; |
|
104 | - } |
|
102 | + if (null !== $this->href && $this->handlesHrefGracefully) { |
|
103 | + $text = "\033]8;;$this->href\033\\$text\033]8;;\033\\"; |
|
104 | + } |
|
105 | 105 | |
106 | - return $this->color->apply($text); |
|
107 | - } |
|
106 | + return $this->color->apply($text); |
|
107 | + } |
|
108 | 108 | } |
@@ -33,28 +33,28 @@ discard block |
||
33 | 33 | * @param string|null $foreground The style foreground color name |
34 | 34 | * @param string|null $background The style background color name |
35 | 35 | */ |
36 | - public function __construct(string $foreground = null, string $background = null, array $options = []) |
|
36 | + public function __construct( string $foreground = null, string $background = null, array $options = [ ] ) |
|
37 | 37 | { |
38 | - $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options); |
|
38 | + $this->color = new Color( $this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * {@inheritdoc} |
43 | 43 | */ |
44 | - public function setForeground(string $color = null) |
|
44 | + public function setForeground( string $color = null ) |
|
45 | 45 | { |
46 | - $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); |
|
46 | + $this->color = new Color( $this->foreground = $color ?: '', $this->background, $this->options ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * {@inheritdoc} |
51 | 51 | */ |
52 | - public function setBackground(string $color = null) |
|
52 | + public function setBackground( string $color = null ) |
|
53 | 53 | { |
54 | - $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); |
|
54 | + $this->color = new Color( $this->foreground, $this->background = $color ?: '', $this->options ); |
|
55 | 55 | } |
56 | 56 | |
57 | - public function setHref(string $url): void |
|
57 | + public function setHref( string $url ): void |
|
58 | 58 | { |
59 | 59 | $this->href = $url; |
60 | 60 | } |
@@ -62,47 +62,47 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * {@inheritdoc} |
64 | 64 | */ |
65 | - public function setOption(string $option) |
|
65 | + public function setOption( string $option ) |
|
66 | 66 | { |
67 | - $this->options[] = $option; |
|
68 | - $this->color = new Color($this->foreground, $this->background, $this->options); |
|
67 | + $this->options[ ] = $option; |
|
68 | + $this->color = new Color( $this->foreground, $this->background, $this->options ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * {@inheritdoc} |
73 | 73 | */ |
74 | - public function unsetOption(string $option) |
|
74 | + public function unsetOption( string $option ) |
|
75 | 75 | { |
76 | - $pos = array_search($option, $this->options); |
|
77 | - if (false !== $pos) { |
|
78 | - unset($this->options[$pos]); |
|
76 | + $pos = array_search( $option, $this->options ); |
|
77 | + if ( false !== $pos ) { |
|
78 | + unset( $this->options[ $pos ] ); |
|
79 | 79 | } |
80 | 80 | |
81 | - $this->color = new Color($this->foreground, $this->background, $this->options); |
|
81 | + $this->color = new Color( $this->foreground, $this->background, $this->options ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * {@inheritdoc} |
86 | 86 | */ |
87 | - public function setOptions(array $options) |
|
87 | + public function setOptions( array $options ) |
|
88 | 88 | { |
89 | - $this->color = new Color($this->foreground, $this->background, $this->options = $options); |
|
89 | + $this->color = new Color( $this->foreground, $this->background, $this->options = $options ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * {@inheritdoc} |
94 | 94 | */ |
95 | - public function apply(string $text) |
|
95 | + public function apply( string $text ) |
|
96 | 96 | { |
97 | - if (null === $this->handlesHrefGracefully) { |
|
98 | - $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') |
|
99 | - && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100); |
|
97 | + if ( null === $this->handlesHrefGracefully ) { |
|
98 | + $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv( 'TERMINAL_EMULATOR' ) |
|
99 | + && ( ! getenv( 'KONSOLE_VERSION' ) || (int)getenv( 'KONSOLE_VERSION' ) > 201100 ); |
|
100 | 100 | } |
101 | 101 | |
102 | - if (null !== $this->href && $this->handlesHrefGracefully) { |
|
102 | + if ( null !== $this->href && $this->handlesHrefGracefully ) { |
|
103 | 103 | $text = "\033]8;;$this->href\033\\$text\033]8;;\033\\"; |
104 | 104 | } |
105 | 105 | |
106 | - return $this->color->apply($text); |
|
106 | + return $this->color->apply( $text ); |
|
107 | 107 | } |
108 | 108 | } |
@@ -18,8 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @author Konstantin Kudryashov <[email protected]> |
20 | 20 | */ |
21 | -class OutputFormatterStyle implements OutputFormatterStyleInterface |
|
22 | -{ |
|
21 | +class OutputFormatterStyle implements OutputFormatterStyleInterface { |
|
23 | 22 | private $color; |
24 | 23 | private $foreground; |
25 | 24 | private $background; |
@@ -33,24 +32,21 @@ discard block |
||
33 | 32 | * @param string|null $foreground The style foreground color name |
34 | 33 | * @param string|null $background The style background color name |
35 | 34 | */ |
36 | - public function __construct(string $foreground = null, string $background = null, array $options = []) |
|
37 | - { |
|
35 | + public function __construct(string $foreground = null, string $background = null, array $options = []) { |
|
38 | 36 | $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options); |
39 | 37 | } |
40 | 38 | |
41 | 39 | /** |
42 | 40 | * {@inheritdoc} |
43 | 41 | */ |
44 | - public function setForeground(string $color = null) |
|
45 | - { |
|
42 | + public function setForeground(string $color = null) { |
|
46 | 43 | $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); |
47 | 44 | } |
48 | 45 | |
49 | 46 | /** |
50 | 47 | * {@inheritdoc} |
51 | 48 | */ |
52 | - public function setBackground(string $color = null) |
|
53 | - { |
|
49 | + public function setBackground(string $color = null) { |
|
54 | 50 | $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); |
55 | 51 | } |
56 | 52 | |
@@ -62,8 +58,7 @@ discard block |
||
62 | 58 | /** |
63 | 59 | * {@inheritdoc} |
64 | 60 | */ |
65 | - public function setOption(string $option) |
|
66 | - { |
|
61 | + public function setOption(string $option) { |
|
67 | 62 | $this->options[] = $option; |
68 | 63 | $this->color = new Color($this->foreground, $this->background, $this->options); |
69 | 64 | } |
@@ -71,8 +66,7 @@ discard block |
||
71 | 66 | /** |
72 | 67 | * {@inheritdoc} |
73 | 68 | */ |
74 | - public function unsetOption(string $option) |
|
75 | - { |
|
69 | + public function unsetOption(string $option) { |
|
76 | 70 | $pos = array_search($option, $this->options); |
77 | 71 | if (false !== $pos) { |
78 | 72 | unset($this->options[$pos]); |
@@ -84,16 +78,14 @@ discard block |
||
84 | 78 | /** |
85 | 79 | * {@inheritdoc} |
86 | 80 | */ |
87 | - public function setOptions(array $options) |
|
88 | - { |
|
81 | + public function setOptions(array $options) { |
|
89 | 82 | $this->color = new Color($this->foreground, $this->background, $this->options = $options); |
90 | 83 | } |
91 | 84 | |
92 | 85 | /** |
93 | 86 | * {@inheritdoc} |
94 | 87 | */ |
95 | - public function apply(string $text) |
|
96 | - { |
|
88 | + public function apply(string $text) { |
|
97 | 89 | if (null === $this->handlesHrefGracefully) { |
98 | 90 | $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') |
99 | 91 | && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100); |
@@ -16,57 +16,57 @@ |
||
16 | 16 | */ |
17 | 17 | final class NullOutputFormatter implements OutputFormatterInterface |
18 | 18 | { |
19 | - private $style; |
|
19 | + private $style; |
|
20 | 20 | |
21 | - /** |
|
22 | - * {@inheritdoc} |
|
23 | - */ |
|
24 | - public function format(?string $message): void |
|
25 | - { |
|
26 | - // do nothing |
|
27 | - } |
|
21 | + /** |
|
22 | + * {@inheritdoc} |
|
23 | + */ |
|
24 | + public function format(?string $message): void |
|
25 | + { |
|
26 | + // do nothing |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * {@inheritdoc} |
|
31 | - */ |
|
32 | - public function getStyle(string $name): OutputFormatterStyleInterface |
|
33 | - { |
|
34 | - if ($this->style) { |
|
35 | - return $this->style; |
|
36 | - } |
|
37 | - // to comply with the interface we must return a OutputFormatterStyleInterface |
|
38 | - return $this->style = new NullOutputFormatterStyle(); |
|
39 | - } |
|
29 | + /** |
|
30 | + * {@inheritdoc} |
|
31 | + */ |
|
32 | + public function getStyle(string $name): OutputFormatterStyleInterface |
|
33 | + { |
|
34 | + if ($this->style) { |
|
35 | + return $this->style; |
|
36 | + } |
|
37 | + // to comply with the interface we must return a OutputFormatterStyleInterface |
|
38 | + return $this->style = new NullOutputFormatterStyle(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * {@inheritdoc} |
|
43 | - */ |
|
44 | - public function hasStyle(string $name): bool |
|
45 | - { |
|
46 | - return false; |
|
47 | - } |
|
41 | + /** |
|
42 | + * {@inheritdoc} |
|
43 | + */ |
|
44 | + public function hasStyle(string $name): bool |
|
45 | + { |
|
46 | + return false; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function isDecorated(): bool |
|
53 | - { |
|
54 | - return false; |
|
55 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function isDecorated(): bool |
|
53 | + { |
|
54 | + return false; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * {@inheritdoc} |
|
59 | - */ |
|
60 | - public function setDecorated(bool $decorated): void |
|
61 | - { |
|
62 | - // do nothing |
|
63 | - } |
|
57 | + /** |
|
58 | + * {@inheritdoc} |
|
59 | + */ |
|
60 | + public function setDecorated(bool $decorated): void |
|
61 | + { |
|
62 | + // do nothing |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * {@inheritdoc} |
|
67 | - */ |
|
68 | - public function setStyle(string $name, OutputFormatterStyleInterface $style): void |
|
69 | - { |
|
70 | - // do nothing |
|
71 | - } |
|
65 | + /** |
|
66 | + * {@inheritdoc} |
|
67 | + */ |
|
68 | + public function setStyle(string $name, OutputFormatterStyleInterface $style): void |
|
69 | + { |
|
70 | + // do nothing |
|
71 | + } |
|
72 | 72 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * {@inheritdoc} |
23 | 23 | */ |
24 | - public function format(?string $message): void |
|
24 | + public function format( ?string $message ): void |
|
25 | 25 | { |
26 | 26 | // do nothing |
27 | 27 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | /** |
30 | 30 | * {@inheritdoc} |
31 | 31 | */ |
32 | - public function getStyle(string $name): OutputFormatterStyleInterface |
|
32 | + public function getStyle( string $name ): OutputFormatterStyleInterface |
|
33 | 33 | { |
34 | - if ($this->style) { |
|
34 | + if ( $this->style ) { |
|
35 | 35 | return $this->style; |
36 | 36 | } |
37 | 37 | // to comply with the interface we must return a OutputFormatterStyleInterface |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * {@inheritdoc} |
43 | 43 | */ |
44 | - public function hasStyle(string $name): bool |
|
44 | + public function hasStyle( string $name ): bool |
|
45 | 45 | { |
46 | 46 | return false; |
47 | 47 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * {@inheritdoc} |
59 | 59 | */ |
60 | - public function setDecorated(bool $decorated): void |
|
60 | + public function setDecorated( bool $decorated ): void |
|
61 | 61 | { |
62 | 62 | // do nothing |
63 | 63 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * {@inheritdoc} |
67 | 67 | */ |
68 | - public function setStyle(string $name, OutputFormatterStyleInterface $style): void |
|
68 | + public function setStyle( string $name, OutputFormatterStyleInterface $style ): void |
|
69 | 69 | { |
70 | 70 | // do nothing |
71 | 71 | } |
@@ -14,8 +14,7 @@ |
||
14 | 14 | /** |
15 | 15 | * @author Tien Xuan Vo <[email protected]> |
16 | 16 | */ |
17 | -final class NullOutputFormatter implements OutputFormatterInterface |
|
18 | -{ |
|
17 | +final class NullOutputFormatter implements OutputFormatterInterface { |
|
19 | 18 | private $style; |
20 | 19 | |
21 | 20 | /** |
@@ -18,35 +18,35 @@ |
||
18 | 18 | */ |
19 | 19 | interface OutputFormatterStyleInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * Sets style foreground color. |
|
23 | - */ |
|
24 | - public function setForeground(string $color = null); |
|
25 | - |
|
26 | - /** |
|
27 | - * Sets style background color. |
|
28 | - */ |
|
29 | - public function setBackground(string $color = null); |
|
30 | - |
|
31 | - /** |
|
32 | - * Sets some specific style option. |
|
33 | - */ |
|
34 | - public function setOption(string $option); |
|
35 | - |
|
36 | - /** |
|
37 | - * Unsets some specific style option. |
|
38 | - */ |
|
39 | - public function unsetOption(string $option); |
|
40 | - |
|
41 | - /** |
|
42 | - * Sets multiple style options at once. |
|
43 | - */ |
|
44 | - public function setOptions(array $options); |
|
45 | - |
|
46 | - /** |
|
47 | - * Applies the style to a given text. |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function apply(string $text); |
|
21 | + /** |
|
22 | + * Sets style foreground color. |
|
23 | + */ |
|
24 | + public function setForeground(string $color = null); |
|
25 | + |
|
26 | + /** |
|
27 | + * Sets style background color. |
|
28 | + */ |
|
29 | + public function setBackground(string $color = null); |
|
30 | + |
|
31 | + /** |
|
32 | + * Sets some specific style option. |
|
33 | + */ |
|
34 | + public function setOption(string $option); |
|
35 | + |
|
36 | + /** |
|
37 | + * Unsets some specific style option. |
|
38 | + */ |
|
39 | + public function unsetOption(string $option); |
|
40 | + |
|
41 | + /** |
|
42 | + * Sets multiple style options at once. |
|
43 | + */ |
|
44 | + public function setOptions(array $options); |
|
45 | + |
|
46 | + /** |
|
47 | + * Applies the style to a given text. |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function apply(string $text); |
|
52 | 52 | } |
@@ -21,32 +21,32 @@ |
||
21 | 21 | /** |
22 | 22 | * Sets style foreground color. |
23 | 23 | */ |
24 | - public function setForeground(string $color = null); |
|
24 | + public function setForeground( string $color = null ); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Sets style background color. |
28 | 28 | */ |
29 | - public function setBackground(string $color = null); |
|
29 | + public function setBackground( string $color = null ); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Sets some specific style option. |
33 | 33 | */ |
34 | - public function setOption(string $option); |
|
34 | + public function setOption( string $option ); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Unsets some specific style option. |
38 | 38 | */ |
39 | - public function unsetOption(string $option); |
|
39 | + public function unsetOption( string $option ); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Sets multiple style options at once. |
43 | 43 | */ |
44 | - public function setOptions(array $options); |
|
44 | + public function setOptions( array $options ); |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * Applies the style to a given text. |
48 | 48 | * |
49 | 49 | * @return string |
50 | 50 | */ |
51 | - public function apply(string $text); |
|
51 | + public function apply( string $text ); |
|
52 | 52 | } |
@@ -16,8 +16,7 @@ |
||
16 | 16 | * |
17 | 17 | * @author Konstantin Kudryashov <[email protected]> |
18 | 18 | */ |
19 | -interface OutputFormatterStyleInterface |
|
20 | -{ |
|
19 | +interface OutputFormatterStyleInterface { |
|
21 | 20 | /** |
22 | 21 | * Sets style foreground color. |
23 | 22 | */ |