|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
// 17.03.23 |
|
5
|
|
|
namespace AlecRabbit\Spinner\Core\A; |
|
6
|
|
|
|
|
7
|
|
|
use AlecRabbit\Spinner\Contract\IDriver; |
|
8
|
|
|
use AlecRabbit\Spinner\Contract\ITimer; |
|
9
|
|
|
use AlecRabbit\Spinner\Core\Contract\IDriverBuilder; |
|
10
|
|
|
use AlecRabbit\Spinner\Core\Defaults\Contract\IDefaults; |
|
11
|
|
|
use AlecRabbit\Spinner\Core\Defaults\Contract\IDriverSettings; |
|
12
|
|
|
use AlecRabbit\Spinner\Core\Defaults\Contract\ITerminalSettings; |
|
13
|
|
|
use AlecRabbit\Spinner\Core\Driver; |
|
14
|
|
|
use AlecRabbit\Spinner\Core\Output\Contract\IOutput; |
|
15
|
|
|
use AlecRabbit\Spinner\Core\Output\StreamOutput; |
|
16
|
|
|
use AlecRabbit\Spinner\Core\Timer; |
|
17
|
|
|
|
|
18
|
|
|
abstract class ADriverBuilder implements IDriverBuilder |
|
19
|
|
|
{ |
|
20
|
|
|
protected ?IDriverSettings $driverSettings = null; |
|
21
|
|
|
protected ?IOutput $output = null; |
|
22
|
|
|
protected ?ITerminalSettings $terminalSettings = null; |
|
23
|
|
|
protected ?ITimer $timer = null; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct( |
|
26
|
|
|
protected IDefaults $defaults, |
|
27
|
|
|
) { |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @inheritDoc |
|
32
|
|
|
*/ |
|
33
|
|
|
public function build(): IDriver |
|
34
|
|
|
{ |
|
35
|
|
|
$this->output ??= new StreamOutput($this->defaults->getOutputStream()); |
|
36
|
|
|
$this->timer ??= new Timer(); |
|
37
|
|
|
$this->terminalSettings ??= $this->defaults->getTerminalSettings(); |
|
38
|
|
|
$this->driverSettings ??= $this->defaults->getDriverSettings(); |
|
39
|
|
|
|
|
40
|
|
|
return |
|
41
|
|
|
new Driver( |
|
42
|
|
|
output: $this->output, |
|
|
|
|
|
|
43
|
|
|
timer: $this->timer, |
|
|
|
|
|
|
44
|
|
|
hideCursor: $this->terminalSettings->isCursorDisabled(), |
|
45
|
|
|
interruptMessage: $this->driverSettings->getInterruptMessage(), |
|
46
|
|
|
finalMessage: $this->driverSettings->getFinalMessage(), |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function withOutput(IOutput $output): static |
|
51
|
|
|
{ |
|
52
|
|
|
$clone = clone $this; |
|
53
|
|
|
$clone->output = $output; |
|
54
|
|
|
return $clone; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function withTimer(ITimer $timer): static |
|
58
|
|
|
{ |
|
59
|
|
|
$clone = clone $this; |
|
60
|
|
|
$clone->timer = $timer; |
|
61
|
|
|
return $clone; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function withTerminalSettings(ITerminalSettings $terminalSettings): static |
|
65
|
|
|
{ |
|
66
|
|
|
$clone = clone $this; |
|
67
|
|
|
$clone->terminalSettings = $terminalSettings; |
|
68
|
|
|
return $clone; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function withDriverSettings(IDriverSettings $driverSettings): static |
|
72
|
|
|
{ |
|
73
|
|
|
$clone = clone $this; |
|
74
|
|
|
$clone->driverSettings = $driverSettings; |
|
75
|
|
|
return $clone; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
} |