1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
// 10.03.23 |
5
|
|
|
|
6
|
|
|
namespace AlecRabbit\Spinner\Core; |
7
|
|
|
|
8
|
|
|
use AlecRabbit\Spinner\Contract\IFrame; |
9
|
|
|
use AlecRabbit\Spinner\Contract\IFrameCollection; |
10
|
|
|
use AlecRabbit\Spinner\Contract\IFrameCollectionRenderer; |
11
|
|
|
use AlecRabbit\Spinner\Contract\IPattern; |
12
|
|
|
use AlecRabbit\Spinner\Contract\IStyle; |
13
|
|
|
use AlecRabbit\Spinner\Contract\IStyleFrameRenderer; |
14
|
|
|
use AlecRabbit\Spinner\Contract\StyleMode; |
15
|
|
|
use AlecRabbit\Spinner\Core\A\AFrameCollectionRenderer; |
16
|
|
|
use AlecRabbit\Spinner\Core\Factory\FrameFactory; |
17
|
|
|
use AlecRabbit\Spinner\Core\Pattern\Contract\IStylePattern; |
18
|
|
|
use AlecRabbit\Spinner\Exception\InvalidArgumentException; |
19
|
|
|
use ArrayObject; |
20
|
|
|
|
21
|
|
|
final class StyleFrameCollectionRenderer extends AFrameCollectionRenderer |
22
|
|
|
{ |
23
|
|
|
private StyleMode $styleMode = StyleMode::NONE; |
24
|
|
|
|
25
|
|
|
public function __construct( |
26
|
|
|
protected IStyleFrameRenderer $frameRenderer, |
27
|
|
|
) { |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** @inheritdoc */ |
31
|
|
|
public function pattern(IPattern $pattern): IFrameCollectionRenderer |
32
|
|
|
{ |
33
|
|
|
if (!$pattern instanceof IStylePattern) { |
34
|
|
|
throw new InvalidArgumentException( |
35
|
|
|
sprintf( |
36
|
|
|
'Pattern should be instance of "%s", "%s" given.', |
37
|
|
|
IStylePattern::class, |
38
|
|
|
get_debug_type($pattern) |
39
|
|
|
) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$clone = clone $this; |
44
|
|
|
$clone->pattern = $pattern; |
45
|
|
|
$clone->styleMode = $pattern->getStyleMode(); |
46
|
|
|
return $clone; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @throws InvalidArgumentException |
51
|
|
|
*/ |
52
|
|
|
protected function createFrame(string|IStyle $entry): IFrame |
53
|
|
|
{ |
54
|
|
|
return $this->frameRenderer->render($entry, $this->styleMode); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** @inheritdoc */ |
58
|
|
|
public function render(): IFrameCollection |
59
|
|
|
{ |
60
|
|
|
if ($this->frameRenderer->isStylingDisabled()) { |
61
|
|
|
return |
62
|
|
|
$this->createCollectionWithOneStyle(); |
63
|
|
|
} |
64
|
|
|
return parent::render(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @throws InvalidArgumentException |
69
|
|
|
*/ |
70
|
|
|
private function createCollectionWithOneStyle(): FrameCollection |
71
|
|
|
{ |
72
|
|
|
return |
73
|
|
|
$this->createCollection( |
74
|
|
|
new ArrayObject( |
75
|
|
|
[ |
76
|
|
|
FrameFactory::create('%s', 0), // no styling |
77
|
|
|
] |
78
|
|
|
) |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|