1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by 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\Core\Model\ImageInterface; |
16
|
|
|
use Sylius\Component\Resource\Model\TimestampableTrait; |
17
|
|
|
use Sylius\Component\Resource\Model\ToggleableTrait; |
18
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
19
|
|
|
use Sylius\Component\Resource\Model\TranslationInterface; |
20
|
|
|
|
21
|
|
|
class Page implements PageInterface |
22
|
|
|
{ |
23
|
|
|
use ToggleableTrait; |
24
|
|
|
use ProductsAwareTrait; |
25
|
|
|
use SectionableTrait; |
26
|
|
|
use TimestampableTrait; |
27
|
|
|
use ChannelsAwareTrait; |
28
|
|
|
use TranslatableTrait { |
29
|
|
|
__construct as protected initializeTranslationsCollection; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** @var int */ |
33
|
|
|
protected $id; |
34
|
|
|
|
35
|
|
|
/** @var string */ |
36
|
|
|
protected $code; |
37
|
|
|
|
38
|
|
|
public function __construct() |
39
|
|
|
{ |
40
|
|
|
$this->initializeProductsCollection(); |
41
|
|
|
$this->initializeSectionsCollection(); |
42
|
|
|
$this->initializeTranslationsCollection(); |
43
|
|
|
$this->initializeChannelsCollection(); |
44
|
|
|
$this->initializeChannelsCollection(); |
45
|
|
|
|
46
|
|
|
$this->createdAt = new \DateTime(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getId(): ?int |
50
|
|
|
{ |
51
|
|
|
return $this->id; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function setId(?int $id): void |
55
|
|
|
{ |
56
|
|
|
$this->id = $id; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getCode(): ?string |
60
|
|
|
{ |
61
|
|
|
return $this->code; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setCode(?string $code): void |
65
|
|
|
{ |
66
|
|
|
$this->code = $code; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getSlug(): ?string |
70
|
|
|
{ |
71
|
|
|
return $this->getPageTranslation()->getSlug(); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function setSlug(?string $slug): void |
75
|
|
|
{ |
76
|
|
|
$this->getPageTranslation()->setSlug($slug); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getMetaKeywords(): ?string |
80
|
|
|
{ |
81
|
|
|
return $this->getPageTranslation()->getMetaKeywords(); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function setMetaKeywords(?string $metaKeywords): void |
85
|
|
|
{ |
86
|
|
|
$this->getPageTranslation()->setMetaKeywords($metaKeywords); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getMetaDescription(): ?string |
90
|
|
|
{ |
91
|
|
|
return $this->getPageTranslation()->getMetaDescription(); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function setMetaDescription(?string $metaDescription): void |
95
|
|
|
{ |
96
|
|
|
$this->getPageTranslation()->setMetaDescription($metaDescription); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getContent(): ?string |
100
|
|
|
{ |
101
|
|
|
return $this->getPageTranslation()->getContent(); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function setContent(?string $content): void |
105
|
|
|
{ |
106
|
|
|
$this->getPageTranslation()->setContent($content); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getName(): ?string |
110
|
|
|
{ |
111
|
|
|
return $this->getPageTranslation()->getName(); |
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function setName(?string $name): void |
115
|
|
|
{ |
116
|
|
|
$this->getPageTranslation()->setName($name); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getNameWhenLinked(): ?string |
120
|
|
|
{ |
121
|
|
|
return $this->getPageTranslation()->getNameWhenLinked(); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function setNameWhenLinked(?string $nameWhenLinked): void |
125
|
|
|
{ |
126
|
|
|
$this->getPageTranslation()->setNameWhenLinked($nameWhenLinked); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function getDescriptionWhenLinked(): ?string |
130
|
|
|
{ |
131
|
|
|
return $this->getPageTranslation()->getDescriptionWhenLinked(); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function setDescriptionWhenLinked(?string $descriptionWhenLinked): void |
135
|
|
|
{ |
136
|
|
|
$this->getPageTranslation()->setDescriptionWhenLinked($descriptionWhenLinked); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function getBreadcrumb(): ?string |
140
|
|
|
{ |
141
|
|
|
return $this->getPageTranslation()->getBreadcrumb(); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function setBreadcrumb(?string $breadcrumb): void |
145
|
|
|
{ |
146
|
|
|
$this->getPageTranslation()->setBreadcrumb($breadcrumb); |
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function getImage(): ?ImageInterface |
150
|
|
|
{ |
151
|
|
|
return $this->getPageTranslation()->getImage(); |
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function setImage(?ImageInterface $image): void |
155
|
|
|
{ |
156
|
|
|
$this->getPageTranslation()->setImage($image); |
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function getTitle(): ?string |
160
|
|
|
{ |
161
|
|
|
return $this->getPageTranslation()->getTitle(); |
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function setTitle(?string $title): void |
165
|
|
|
{ |
166
|
|
|
$this->getPageTranslation()->setTitle($title); |
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return PageTranslationInterface|TranslationInterface|null |
171
|
|
|
*/ |
172
|
|
|
protected function getPageTranslation(): PageTranslationInterface |
173
|
|
|
{ |
174
|
|
|
return $this->getTranslation(); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
protected function createTranslation(): ?PageTranslationInterface |
178
|
|
|
{ |
179
|
|
|
return new PageTranslation(); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|
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: