1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of tenside/core. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Schiffler <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* This project is provided in good faith and hope to be usable by anyone. |
12
|
|
|
* |
13
|
|
|
* @package tenside/core |
14
|
|
|
* @author Christian Schiffler <[email protected]> |
15
|
|
|
* @copyright 2015 Christian Schiffler <[email protected]> |
16
|
|
|
* @license https://github.com/tenside/core/blob/master/LICENSE MIT |
17
|
|
|
* @link https://github.com/tenside/core |
18
|
|
|
* @filesource |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Tenside\Core\Task; |
22
|
|
|
|
23
|
|
|
use Symfony\Component\Console\Formatter\OutputFormatterInterface; |
24
|
|
|
use Symfony\Component\Console\Output\Output; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Redirecting output to send the output data to the task json file. |
28
|
|
|
*/ |
29
|
|
|
class TaskOutput extends Output |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* The task for which this output is attached to.. |
33
|
|
|
* |
34
|
|
|
* @var Task |
35
|
|
|
*/ |
36
|
|
|
private $task; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create a new instance. |
40
|
|
|
* |
41
|
|
|
* @param Task $task The task being logged to. |
42
|
|
|
* |
43
|
|
|
* @param int $verbosity The verbosity level |
44
|
|
|
* (one of the VERBOSITY constants in OutputInterface). |
45
|
|
|
* |
46
|
|
|
* @param bool $decorated Whether to decorate messages. |
47
|
|
|
* |
48
|
|
|
* @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter) |
49
|
|
|
* |
50
|
|
|
* @api |
51
|
|
|
*/ |
52
|
|
|
public function __construct( |
53
|
|
|
Task $task, |
54
|
|
|
$verbosity = self::VERBOSITY_NORMAL, |
55
|
|
|
$decorated = false, |
56
|
|
|
OutputFormatterInterface $formatter = null |
57
|
|
|
) { |
58
|
|
|
parent::__construct($verbosity, $decorated, $formatter); |
59
|
|
|
|
60
|
|
|
$this->task = $task; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Fetch buffer content. |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function fetch() |
69
|
|
|
{ |
70
|
|
|
return $this->task->getOutput(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
protected function doWrite($message, $newline) |
77
|
|
|
{ |
78
|
|
|
if ($newline) { |
79
|
|
|
$message .= "\n"; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$this->task->addOutput($message); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|