-
Notifications
You must be signed in to change notification settings - Fork 1
/
Run.php
126 lines (107 loc) · 2.03 KB
/
Run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* @author Jared King <j@jaredtking.com>
*
* @see http://jaredtking.com
*
* @copyright 2015 Jared King
* @license MIT
*/
namespace Infuse\Cron\Libs;
use Symfony\Component\Console\Output\OutputInterface;
class Run
{
const RESULT_SUCCEEDED = 'succeeded';
const RESULT_LOCKED = 'locked';
const RESULT_FAILED = 'failed';
/**
* @var array
*/
private $output = [];
/**
* @var string
*/
private $result;
/**
* @var OutputInterface
*/
private $consoleOutput;
/**
* Writes output to the run.
*
* @param string $str
*
* @return self
*/
public function writeOutput($str)
{
if (empty($str)) {
return $this;
}
$this->output[] = $str;
if ($this->consoleOutput) {
$this->consoleOutput->writeln($str);
}
return $this;
}
/**
* Gets the output from the run.
*
* @return string
*/
public function getOutput()
{
return trim(implode("\n", $this->output));
}
/**
* Sets the result of the run.
*
* @param string $result
*
* @return self
*/
public function setResult($result)
{
$this->result = $result;
return $this;
}
/**
* Gets the result of the run.
*
* @return string
*/
public function getResult()
{
return $this->result;
}
/**
* Checks if the run succeeded.
*
* @return bool
*/
public function succeeded()
{
return self::RESULT_SUCCEEDED == $this->result;
}
/**
* Checks if the run failed.
*
* @return bool
*/
public function failed()
{
return self::RESULT_FAILED == $this->result;
}
/**
* Sets the console output.
*
* @param OutputInterface $output
*
* @return self
*/
public function setConsoleOutput(OutputInterface $output)
{
$this->consoleOutput = $output;
return $this;
}
}