Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / robo / src / Common / ProgressIndicatorAwareTrait.php
1 <?php
2 namespace Robo\Common;
3
4 use Robo\Contract\ProgressIndicatorAwareInterface;
5 use Robo\Contract\VerbosityThresholdInterface;
6
7 trait ProgressIndicatorAwareTrait
8 {
9     use Timer;
10
11     /**
12      * @var null|\Robo\Common\ProgressIndicator
13      */
14     protected $progressIndicator;
15
16     /**
17      * @return int
18      */
19     public function progressIndicatorSteps()
20     {
21         return 0;
22     }
23
24     /**
25      * @param null|\Robo\Common\ProgressIndicator $progressIndicator
26      *
27      * @return ProgressIndicatorAwareInterface
28      */
29     public function setProgressIndicator($progressIndicator)
30     {
31         $this->progressIndicator = $progressIndicator;
32
33         return $this;
34     }
35
36     /**
37      * @return null|bool
38      */
39     protected function hideProgressIndicator()
40     {
41         if (!$this->progressIndicator) {
42             return;
43         }
44         return $this->progressIndicator->hideProgressIndicator();
45     }
46
47     protected function showProgressIndicator()
48     {
49         if (!$this->progressIndicator) {
50             return;
51         }
52         $this->progressIndicator->showProgressIndicator();
53     }
54
55     /**
56      * @param bool $visible
57      */
58     protected function restoreProgressIndicator($visible)
59     {
60         if (!$this->progressIndicator) {
61             return;
62         }
63         $this->progressIndicator->restoreProgressIndicator($visible);
64     }
65
66     /**
67      * @return int
68      */
69     protected function getTotalExecutionTime()
70     {
71         if (!$this->progressIndicator) {
72             return 0;
73         }
74         return $this->progressIndicator->getExecutionTime();
75     }
76
77     protected function startProgressIndicator()
78     {
79         $this->startTimer();
80         if ($this instanceof VerbosityThresholdInterface
81             && !$this->verbosityMeetsThreshold()) {
82             return;
83         }
84         if (!$this->progressIndicator) {
85             return;
86         }
87         $totalSteps = $this->progressIndicatorSteps();
88         $this->progressIndicator->startProgressIndicator($totalSteps, $this);
89     }
90
91     /**
92      * @return bool
93      */
94     protected function inProgress()
95     {
96         if (!$this->progressIndicator) {
97             return false;
98         }
99         return $this->progressIndicator->inProgress();
100     }
101
102     protected function stopProgressIndicator()
103     {
104         $this->stopTimer();
105         if (!$this->progressIndicator) {
106             return;
107         }
108         $this->progressIndicator->stopProgressIndicator($this);
109     }
110
111     protected function disableProgressIndicator()
112     {
113         $this->stopTimer();
114         if (!$this->progressIndicator) {
115             return;
116         }
117         $this->progressIndicator->disableProgressIndicator();
118     }
119
120     protected function detatchProgressIndicator()
121     {
122         $this->setProgressIndicator(null);
123     }
124
125     /**
126      * @param int $steps
127      */
128     protected function advanceProgressIndicator($steps = 1)
129     {
130         if (!$this->progressIndicator) {
131             return;
132         }
133         $this->progressIndicator->advanceProgressIndicator($steps);
134     }
135 }