|
1
|
|
|
<?php |
|
2
|
|
|
namespace Robo\Common; |
|
3
|
|
|
|
|
4
|
|
|
use Robo\Robo; |
|
5
|
|
|
use Robo\TaskInfo; |
|
6
|
|
|
use Robo\Contract\OutputAdapterInterface; |
|
7
|
|
|
use Robo\Contract\VerbosityThresholdInterface; |
|
8
|
|
|
use Consolidation\Log\ConsoleLogLevel; |
|
9
|
|
|
use Psr\Log\LoggerAwareTrait; |
|
10
|
|
|
use Psr\Log\LogLevel; |
|
11
|
|
|
use Robo\Contract\ProgressIndicatorAwareInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Task input/output methods. TaskIO is 'used' in BaseTask, so any |
|
16
|
|
|
* task that extends this class has access to all of the methods here. |
|
17
|
|
|
* printTaskInfo, printTaskSuccess, and printTaskError are the three |
|
18
|
|
|
* primary output methods that tasks are encouraged to use. Tasks should |
|
19
|
|
|
* avoid using the IO trait output methods. |
|
20
|
|
|
*/ |
|
21
|
|
|
trait VerbosityThresholdTrait |
|
22
|
|
|
{ |
|
23
|
|
|
/** var OutputAdapterInterface */ |
|
24
|
|
|
protected $outputAdapter; |
|
25
|
|
|
protected $verbosityThreshold = 0; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Required verbocity level before any TaskIO output will be produced. |
|
29
|
|
|
* e.g. OutputInterface::VERBOSITY_VERBOSE |
|
30
|
|
|
*/ |
|
31
|
|
|
public function setVerbosityThreshold($verbosityThreshold) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->verbosityThreshold = $verbosityThreshold; |
|
34
|
|
|
return $this; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function verbosityThreshold() |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->verbosityThreshold; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function setOutputAdapter(OutputAdapterInterface $outputAdapter) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->outputAdapter = $outputAdapter; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return OutputAdapterInterface |
|
49
|
|
|
*/ |
|
50
|
|
|
public function outputAdapter() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->outputAdapter; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function hasOutputAdapter() |
|
56
|
|
|
{ |
|
57
|
|
|
return isset($this->outputAdapter); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function verbosityMeetsThreshold() |
|
61
|
|
|
{ |
|
62
|
|
|
if ($this->hasOutputAdapter()) { |
|
63
|
|
|
return $this->outputAdapter()->verbosityMeetsThreshold($this->verbosityThreshold()); |
|
64
|
|
|
} |
|
65
|
|
|
return true; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Print a message if the selected verbosity level is over this task's |
|
70
|
|
|
* verbosity threshhold. |
|
71
|
|
|
*/ |
|
72
|
|
|
public function writeMessage($message) |
|
73
|
|
|
{ |
|
74
|
|
|
if (!$this->verbosityMeetsThreshold()) { |
|
75
|
|
|
return; |
|
76
|
|
|
} |
|
77
|
|
|
$this->outputAdapter()->writeMessage($message); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|