1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace Codeception\Lib\Console;
use Symfony\Component\Console\Output\OutputInterface;
class Message
{
protected $output;
protected $message;
public function __construct($message, Output $output = null)
{
$this->message = $message;
$this->output = $output;
}
public function with($param)
{
$args = array_merge([$this->message], func_get_args());
$this->message = call_user_func_array('sprintf', $args);
return $this;
}
public function style($name)
{
$this->message = sprintf('<%s>%s</%s>', $name, $this->message, $name);
return $this;
}
public function width($length, $char = ' ')
{
$message_length = $this->getLength();
if ($message_length < $length) {
$this->message .= str_repeat($char, $length - $message_length);
}
return $this;
}
public function cut($length)
{
$this->message = mb_substr($this->message, 0, $length, 'utf-8');
return $this;
}
public function write($verbose = OutputInterface::VERBOSITY_NORMAL)
{
if ($verbose > $this->output->getVerbosity()) {
return;
}
$this->output->write($this->message);
}
public function writeln($verbose = OutputInterface::VERBOSITY_NORMAL)
{
if ($verbose > $this->output->getVerbosity()) {
return;
}
$this->output->writeln($this->message);
}
public function prepend($string)
{
if ($string instanceof Message) {
$string = $string->getMessage();
}
$this->message = $string . $this->message;
return $this;
}
public function append($string)
{
if ($string instanceof Message) {
$string = $string->getMessage();
}
$this->message .= $string;
return $this;
}
public function apply($func)
{
$this->message = call_user_func($func, $this->message);
return $this;
}
public function center($char)
{
$this->message = $char . $this->message . $char;
return $this;
}
/**
* @return mixed
*/
public function getMessage()
{
return $this->message;
}
public function block($style)
{
$this->message = $this->output->formatHelper->formatBlock($this->message, $style, true);
return $this;
}
public function getLength($includeTags = false)
{
return mb_strwidth($includeTags ? $this->message : strip_tags($this->message), 'utf-8');
}
public static function ucfirst($text)
{
return mb_strtoupper(mb_substr($text, 0, 1, 'utf-8'), 'utf-8') . mb_substr($text, 1, null, 'utf-8');
}
public function __toString()
{
return $this->message;
}
}