|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\UiBundle\Registry; |
|
15
|
|
|
|
|
16
|
|
|
final class TemplateBlock |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var string */ |
|
19
|
|
|
private $name; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
private $eventName; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string|null */ |
|
25
|
|
|
private $template; |
|
26
|
|
|
|
|
27
|
|
|
/** @var array|null */ |
|
28
|
|
|
private $context; |
|
29
|
|
|
|
|
30
|
|
|
/** @var int|null */ |
|
31
|
|
|
private $priority; |
|
32
|
|
|
|
|
33
|
|
|
/** @var bool|null */ |
|
34
|
|
|
private $enabled; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct( |
|
37
|
|
|
string $name, |
|
38
|
|
|
string $eventName, |
|
39
|
|
|
?string $template, |
|
40
|
|
|
?array $context, |
|
41
|
|
|
?int $priority, |
|
42
|
|
|
?bool $enabled |
|
43
|
|
|
) { |
|
44
|
|
|
$this->name = $name; |
|
45
|
|
|
$this->eventName = $eventName; |
|
46
|
|
|
$this->template = $template; |
|
47
|
|
|
$this->context = $context; |
|
48
|
|
|
$this->priority = $priority; |
|
49
|
|
|
$this->enabled = $enabled; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getName(): string |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->name; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getEventName(): string |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->eventName; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getTemplate(): string |
|
63
|
|
|
{ |
|
64
|
|
|
if ($this->template === null) { |
|
65
|
|
|
throw new \DomainException(sprintf( |
|
66
|
|
|
'There is no template defined for block "%s" in event "%s".', |
|
67
|
|
|
$this->name, |
|
68
|
|
|
$this->eventName |
|
69
|
|
|
)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $this->template; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getContext(): array |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->context ?? []; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function getPriority(): int |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->priority ?? 0; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function isEnabled(): bool |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->enabled ?? true; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function overwriteWith(self $block): self |
|
91
|
|
|
{ |
|
92
|
|
|
if ($this->name !== $block->name) { |
|
93
|
|
|
throw new \DomainException(sprintf( |
|
94
|
|
|
'Trying to overwrite block "%s" with block "%s".', |
|
95
|
|
|
$this->name, |
|
96
|
|
|
$block->name |
|
97
|
|
|
)); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return new self( |
|
101
|
|
|
$this->name, |
|
102
|
|
|
$block->eventName, |
|
103
|
|
|
$block->template ?? $this->template, |
|
104
|
|
|
$block->context ?? $this->context, |
|
105
|
|
|
$block->priority ?? $this->priority, |
|
106
|
|
|
$block->enabled ?? $this->enabled |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|