Repository navigation
Expand file tree
/
Copy pathMessage.php
More file actions
110 lines (89 loc) · 2.39 KB
/
Copy pathMessage.php
File metadata and controls
110 lines (89 loc) · 2.39 KB
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
<?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(array($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 = strlen(strip_tags($this->message));
if ($message_length < $length) {
$this->message .= str_repeat($char, $length - $message_length);
}
// todo: cut?
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 __toString()
{
return $this->message;
}
}