1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace JoppeDc\SyliusBetterSeoPlugin\Entity; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\Collection; |
8
|
|
|
use Sylius\Component\Product\Model\ProductInterface; |
|
|
|
|
9
|
|
|
use Sylius\Component\Resource\Model\ResourceInterface; |
10
|
|
|
use Sylius\Component\Resource\Model\TranslatableInterface; |
11
|
|
|
use Sylius\Component\Resource\Model\TranslatableTrait; |
12
|
|
|
use Sylius\Component\Resource\Model\TranslationInterface; |
13
|
|
|
|
14
|
|
|
class ProductSeo implements TranslatableInterface, ResourceInterface |
15
|
|
|
{ |
16
|
|
|
use TranslatableTrait { |
17
|
|
|
__construct as private initializeTranslationsCollection; |
18
|
|
|
getTranslation as private doGetTranslation; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var int|null |
23
|
|
|
*/ |
24
|
|
|
protected $id; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var ProductInterface|null |
28
|
|
|
*/ |
29
|
|
|
private $product; |
30
|
|
|
|
31
|
|
|
public function __construct() |
32
|
|
|
{ |
33
|
|
|
$this->initializeTranslationsCollection(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function __toString() |
37
|
|
|
{ |
38
|
|
|
return (string) $this->getId(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getPageTitle(): ?string |
42
|
|
|
{ |
43
|
|
|
return $this->getTranslation()->getPageTitle(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function setPageTitle(?string $pageTitle): void |
47
|
|
|
{ |
48
|
|
|
$this->getTranslation()->setPageTitle($pageTitle); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getOgTitle(): ?string |
52
|
|
|
{ |
53
|
|
|
return $this->getTranslation()->getOgTitle(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function setOgTitle(?string $ogTitle): void |
57
|
|
|
{ |
58
|
|
|
$this->getTranslation()->setOgTitle($ogTitle); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getOgDescription(): ?string |
62
|
|
|
{ |
63
|
|
|
return $this->getTranslation()->getOgDescription(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function setOgDescription(?string $ogDescription): void |
67
|
|
|
{ |
68
|
|
|
$this->getTranslation()->setOgDescription($ogDescription); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getTwitterTitle(): ?string |
72
|
|
|
{ |
73
|
|
|
return $this->getTranslation()->getTwitterTitle(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function setTwitterTitle(?string $twitterTitle): void |
77
|
|
|
{ |
78
|
|
|
$this->getTranslation()->setTwitterTitle($twitterTitle); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getTwitterDescription(): ?string |
82
|
|
|
{ |
83
|
|
|
return $this->getTranslation()->getTwitterDescription(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function setTwitterDescription(?string $twitterDescription): void |
87
|
|
|
{ |
88
|
|
|
$this->getTranslation()->setTwitterDescription($twitterDescription); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getTwitterSite(): ?string |
92
|
|
|
{ |
93
|
|
|
return $this->getTranslation()->getTwitterSite(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setTwitterSite(?string $twitterSite): void |
97
|
|
|
{ |
98
|
|
|
$this->getTranslation()->setTwitterSite($twitterSite); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getExtraTags(): ?string |
102
|
|
|
{ |
103
|
|
|
return $this->getTranslation()->getExtraTags(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function setExtraTags(?string $extraTags): void |
107
|
|
|
{ |
108
|
|
|
$this->getTranslation()->setExtraTags($extraTags); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getImage(): ?ProductSeoTranslationImage |
112
|
|
|
{ |
113
|
|
|
$images = $this->getTranslation()->getImages(); |
114
|
|
|
|
115
|
|
|
return count($images) ? $images->first() : null; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getId() |
119
|
|
|
{ |
120
|
|
|
return $this->id; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function setId(?int $id): void |
124
|
|
|
{ |
125
|
|
|
$this->id = $id; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return ProductSeoTranslation |
130
|
|
|
*/ |
131
|
|
|
public function getTranslation(?string $locale = null): TranslationInterface |
132
|
|
|
{ |
133
|
|
|
/** @var ProductSeoTranslation $translation */ |
134
|
|
|
$translation = $this->doGetTranslation($locale); |
135
|
|
|
|
136
|
|
|
return $translation; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function getProduct(): ?ProductInterface |
140
|
|
|
{ |
141
|
|
|
return $this->product; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function setProduct(?ProductInterface $product): void |
145
|
|
|
{ |
146
|
|
|
$this->product = $product; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
protected function createTranslation(): ProductSeoTranslation |
150
|
|
|
{ |
151
|
|
|
return new ProductSeoTranslation(); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: