6 use Robo\Contract\OutputAdapterInterface;
7 use Robo\Contract\VerbosityThresholdInterface;
8 use Consolidation\Log\ConsoleLogLevel;
9 use Psr\Log\LoggerAwareTrait;
11 use Robo\Contract\ProgressIndicatorAwareInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
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.
21 trait VerbosityThresholdTrait
23 /** var OutputAdapterInterface */
24 protected $outputAdapter;
25 protected $verbosityThreshold = 0;
28 * Required verbocity level before any TaskIO output will be produced.
29 * e.g. OutputInterface::VERBOSITY_VERBOSE
31 public function setVerbosityThreshold($verbosityThreshold)
33 $this->verbosityThreshold = $verbosityThreshold;
37 public function verbosityThreshold()
39 return $this->verbosityThreshold;
42 public function setOutputAdapter(OutputAdapterInterface $outputAdapter)
44 $this->outputAdapter = $outputAdapter;
48 * @return OutputAdapterInterface
50 public function outputAdapter()
52 return $this->outputAdapter;
55 public function hasOutputAdapter()
57 return isset($this->outputAdapter);
60 public function verbosityMeetsThreshold()
62 if ($this->hasOutputAdapter()) {
63 return $this->outputAdapter()->verbosityMeetsThreshold($this->verbosityThreshold());
69 * Print a message if the selected verbosity level is over this task's
70 * verbosity threshhold.
72 public function writeMessage($message)
74 if (!$this->verbosityMeetsThreshold()) {
77 $this->outputAdapter()->writeMessage($message);