1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file was created by the developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusCmsPlugin\Entity; |
14
|
|
|
|
15
|
|
|
use Sylius\Component\Resource\Model\TimestampableTrait; |
16
|
|
|
use Sylius\Component\Resource\Model\ToggleableTrait; |
17
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
18
|
|
|
use Sylius\Component\Resource\Model\TranslationInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Mikołaj Król <[email protected]> |
22
|
|
|
* @author Patryk Drapik <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class Page implements PageInterface |
25
|
|
|
{ |
26
|
|
|
use ToggleableTrait; |
27
|
|
|
use ProductsAwareTrait; |
28
|
|
|
use SectionableTrait; |
29
|
|
|
use TimestampableTrait; |
30
|
|
|
use TranslatableTrait { |
31
|
|
|
__construct as protected initializeTranslationsCollection; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var null|int |
36
|
|
|
*/ |
37
|
|
|
protected $id; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var null|string |
41
|
|
|
*/ |
42
|
|
|
protected $code; |
43
|
|
|
|
44
|
|
|
public function __construct() |
45
|
|
|
{ |
46
|
|
|
$this->initializeProductsCollection(); |
47
|
|
|
$this->initializeSectionsCollection(); |
48
|
|
|
$this->initializeTranslationsCollection(); |
49
|
|
|
|
50
|
|
|
$this->createdAt = new \DateTime(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function getId(): ?int |
57
|
|
|
{ |
58
|
|
|
return $this->id; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function setId(?int $id): void |
65
|
|
|
{ |
66
|
|
|
$this->id = $id; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
public function getCode(): ?string |
73
|
|
|
{ |
74
|
|
|
return $this->code; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* {@inheritdoc} |
79
|
|
|
*/ |
80
|
|
|
public function setCode(?string $code): void |
81
|
|
|
{ |
82
|
|
|
$this->code = $code; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function getSlug(): ?string |
89
|
|
|
{ |
90
|
|
|
return $this->getPageTranslation()->getSlug(); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
public function setSlug(?string $slug): void |
97
|
|
|
{ |
98
|
|
|
$this->getPageTranslation()->setSlug($slug); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* {@inheritdoc} |
103
|
|
|
*/ |
104
|
|
|
public function getMetaKeywords(): ?string |
105
|
|
|
{ |
106
|
|
|
return $this->getPageTranslation()->getMetaKeywords(); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* {@inheritdoc} |
111
|
|
|
*/ |
112
|
|
|
public function setMetaKeywords(?string $metaKeywords): void |
113
|
|
|
{ |
114
|
|
|
$this->getPageTranslation()->setMetaKeywords($metaKeywords); |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* {@inheritdoc} |
119
|
|
|
*/ |
120
|
|
|
public function getMetaDescription(): ?string |
121
|
|
|
{ |
122
|
|
|
return $this->getPageTranslation()->getMetaDescription(); |
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* {@inheritdoc} |
127
|
|
|
*/ |
128
|
|
|
public function setMetaDescription(?string $metaDescription): void |
129
|
|
|
{ |
130
|
|
|
$this->getPageTranslation()->setMetaDescription($metaDescription); |
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* {@inheritdoc} |
135
|
|
|
*/ |
136
|
|
|
public function getContent(): ?string |
137
|
|
|
{ |
138
|
|
|
return $this->getPageTranslation()->getContent(); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* {@inheritdoc} |
143
|
|
|
*/ |
144
|
|
|
public function setContent(?string $content): void |
145
|
|
|
{ |
146
|
|
|
$this->getPageTranslation()->setContent($content); |
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* {@inheritdoc} |
151
|
|
|
*/ |
152
|
|
|
public function getName(): ?string |
153
|
|
|
{ |
154
|
|
|
return $this->getPageTranslation()->getName(); |
|
|
|
|
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* {@inheritdoc} |
159
|
|
|
*/ |
160
|
|
|
public function setName(?string $name): void |
161
|
|
|
{ |
162
|
|
|
$this->getPageTranslation()->setName($name); |
|
|
|
|
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return PageTranslationInterface|TranslationInterface|null |
167
|
|
|
*/ |
168
|
|
|
protected function getPageTranslation(): PageTranslationInterface |
169
|
|
|
{ |
170
|
|
|
return $this->getTranslation(); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* {@inheritdoc} |
175
|
|
|
*/ |
176
|
|
|
protected function createTranslation(): ?PageTranslationInterface |
177
|
|
|
{ |
178
|
|
|
return new PageTranslation(); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: