Skip to content

Commit dc04752

Browse files
author
roadiz-ci
committed
feat: Better overridability for WebResponses
1 parent f9526d1 commit dc04752

File tree

5 files changed

+133
-169
lines changed

5 files changed

+133
-169
lines changed

src/Api/DataTransformer/WebResponseOutputDataTransformer.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,15 @@ class WebResponseOutputDataTransformer implements WebResponseDataTransformerInte
2525
use BlocksAwareWebResponseOutputDataTransformerTrait;
2626
use RealmsAwareWebResponseOutputDataTransformerTrait;
2727

28-
private NodesSourcesHeadFactoryInterface $nodesSourcesHeadFactory;
29-
private BreadcrumbsFactoryInterface $breadcrumbsFactory;
30-
private WalkerContextInterface $walkerContext;
31-
private CacheItemPoolInterface $cacheItemPool;
32-
private UrlGeneratorInterface $urlGenerator;
33-
private RealmResolverInterface $realmResolver;
34-
private TreeWalkerGenerator $treeWalkerGenerator;
35-
3628
public function __construct(
37-
NodesSourcesHeadFactoryInterface $nodesSourcesHeadFactory,
38-
BreadcrumbsFactoryInterface $breadcrumbsFactory,
39-
WalkerContextInterface $walkerContext,
40-
CacheItemPoolInterface $cacheItemPool,
41-
UrlGeneratorInterface $urlGenerator,
42-
RealmResolverInterface $realmResolver,
43-
TreeWalkerGenerator $treeWalkerGenerator
29+
protected readonly NodesSourcesHeadFactoryInterface $nodesSourcesHeadFactory,
30+
protected readonly BreadcrumbsFactoryInterface $breadcrumbsFactory,
31+
protected readonly WalkerContextInterface $walkerContext,
32+
protected readonly CacheItemPoolInterface $cacheItemPool,
33+
protected readonly UrlGeneratorInterface $urlGenerator,
34+
protected readonly RealmResolverInterface $realmResolver,
35+
protected readonly TreeWalkerGenerator $treeWalkerGenerator
4436
) {
45-
$this->nodesSourcesHeadFactory = $nodesSourcesHeadFactory;
46-
$this->breadcrumbsFactory = $breadcrumbsFactory;
47-
$this->walkerContext = $walkerContext;
48-
$this->cacheItemPool = $cacheItemPool;
49-
$this->urlGenerator = $urlGenerator;
50-
$this->realmResolver = $realmResolver;
51-
$this->treeWalkerGenerator = $treeWalkerGenerator;
5237
}
5338

5439
protected function getWalkerContext(): WalkerContextInterface

src/Api/Model/NodesSourcesHead.php

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ public function getMatomoSiteId(): ?string
113113
#[Serializer\Groups(["web_response", "nodes_sources_single", "walker"])]
114114
public function getSiteName(): ?string
115115
{
116-
// site_name
117116
return $this->settingsBag->get('site_name', null) ?? null;
118117
}
119118

@@ -173,9 +172,6 @@ public function isNoIndex(): bool
173172
return false;
174173
}
175174

176-
/**
177-
* @return string|null
178-
*/
179175
#[Serializer\Groups(["web_response", "nodes_sources_single", "walker"])]
180176
public function getPolicyUrl(): ?string
181177
{
@@ -199,63 +195,60 @@ public function getPolicyUrl(): ?string
199195
return null;
200196
}
201197

202-
/**
203-
* @return string|null
204-
*/
205198
#[Serializer\Groups(["web_response", "nodes_sources_single", "walker"])]
206199
public function getMainColor(): ?string
207200
{
208201
return $this->settingsBag->get('main_color', null) ?? null;
209202
}
210203

211-
/**
212-
* @return string|null
213-
*/
214204
#[Serializer\Groups(["web_response", "nodes_sources_single", "walker"])]
215205
public function getFacebookUrl(): ?string
216206
{
217207
return $this->settingsBag->get('facebook_url', null) ?? null;
218208
}
219209

220-
/**
221-
* @return string|null
222-
*/
223210
#[Serializer\Groups(["web_response", "nodes_sources_single", "walker"])]
224211
public function getInstagramUrl(): ?string
225212
{
226213
return $this->settingsBag->get('instagram_url', null) ?? null;
227214
}
228215

229-
/**
230-
* @return string|null
231-
*/
232216
#[Serializer\Groups(["web_response", "nodes_sources_single", "walker"])]
233217
public function getTwitterUrl(): ?string
234218
{
235219
return $this->settingsBag->get('twitter_url', null) ?? null;
236220
}
237221

238-
/**
239-
* @return string|null
240-
*/
241222
#[Serializer\Groups(["web_response", "nodes_sources_single", "walker"])]
242223
public function getYoutubeUrl(): ?string
243224
{
244225
return $this->settingsBag->get('youtube_url', null) ?? null;
245226
}
246227

247-
/**
248-
* @return string|null
249-
*/
250228
#[Serializer\Groups(["nodes_sources_single", "walker"])]
251229
public function getLinkedinUrl(): ?string
252230
{
253231
return $this->settingsBag->get('linkedin_url', null) ?? null;
254232
}
255233

256-
/**
257-
* @return string|null
258-
*/
234+
#[Serializer\Groups(["nodes_sources_single", "walker"])]
235+
public function getSpotifyUrl(): ?string
236+
{
237+
return $this->settingsBag->get('spotify_url', null) ?? null;
238+
}
239+
240+
#[Serializer\Groups(["nodes_sources_single", "walker"])]
241+
public function getSoundcloudUrl(): ?string
242+
{
243+
return $this->settingsBag->get('soundcloud_url', null) ?? null;
244+
}
245+
246+
#[Serializer\Groups(["nodes_sources_single", "walker"])]
247+
public function getTikTokUrl(): ?string
248+
{
249+
return $this->settingsBag->get('tiktok_url', null) ?? null;
250+
}
251+
259252
#[Serializer\Groups(["web_response", "nodes_sources_single", "walker"])]
260253
public function getHomePageUrl(): ?string
261254
{
@@ -268,9 +261,6 @@ public function getHomePageUrl(): ?string
268261
return null;
269262
}
270263

271-
/**
272-
* @return DocumentInterface|null
273-
*/
274264
#[Serializer\Groups(["web_response", "nodes_sources_single"])]
275265
public function getShareImage(): ?DocumentInterface
276266
{
@@ -291,9 +281,6 @@ public function getShareImage(): ?DocumentInterface
291281
return $this->settingsBag->getDocument('share_image') ?? null;
292282
}
293283

294-
/**
295-
* @return TranslationInterface
296-
*/
297284
#[Serializer\Ignore()]
298285
public function getTranslation(): TranslationInterface
299286
{
@@ -303,9 +290,6 @@ public function getTranslation(): TranslationInterface
303290
return $this->defaultTranslation;
304291
}
305292

306-
/**
307-
* @return NodesSources|null
308-
*/
309293
#[Serializer\Ignore()]
310294
public function getHomePage(): ?NodesSources
311295
{

src/Api/Model/NodesSourcesHeadFactory.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,12 @@
1313

1414
final class NodesSourcesHeadFactory implements NodesSourcesHeadFactoryInterface
1515
{
16-
private Settings $settingsBag;
17-
private UrlGeneratorInterface $urlGenerator;
18-
private NodeSourceApi $nodeSourceApi;
19-
private HandlerFactoryInterface $handlerFactory;
20-
21-
/**
22-
* @param Settings $settingsBag
23-
* @param UrlGeneratorInterface $urlGenerator
24-
* @param NodeSourceApi $nodeSourceApi
25-
* @param HandlerFactoryInterface $handlerFactory
26-
*/
2716
public function __construct(
28-
Settings $settingsBag,
29-
UrlGeneratorInterface $urlGenerator,
30-
NodeSourceApi $nodeSourceApi,
31-
HandlerFactoryInterface $handlerFactory
17+
private readonly Settings $settingsBag,
18+
private readonly UrlGeneratorInterface $urlGenerator,
19+
private readonly NodeSourceApi $nodeSourceApi,
20+
private readonly HandlerFactoryInterface $handlerFactory
3221
) {
33-
$this->settingsBag = $settingsBag;
34-
$this->urlGenerator = $urlGenerator;
35-
$this->nodeSourceApi = $nodeSourceApi;
36-
$this->handlerFactory = $handlerFactory;
3722
}
3823

3924
public function createForNodeSource(NodesSources $nodesSources): NodesSourcesHeadInterface

src/Api/Model/WebResponse.php

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -4,100 +4,7 @@
44

55
namespace RZ\Roadiz\CoreBundle\Api\Model;
66

7-
use ApiPlatform\Metadata\ApiProperty;
8-
use Doctrine\Common\Collections\Collection;
9-
use RZ\Roadiz\Core\AbstractEntities\PersistableInterface;
10-
use RZ\Roadiz\CoreBundle\Api\Breadcrumbs\BreadcrumbsInterface;
11-
use RZ\Roadiz\CoreBundle\Model\RealmInterface;
12-
use RZ\TreeWalker\WalkerInterface;
13-
use Symfony\Component\Serializer\Annotation as Serializer;
14-
157
final class WebResponse implements WebResponseInterface, BlocksAwareWebResponseInterface, RealmsAwareWebResponseInterface
168
{
17-
#[ApiProperty(identifier: true)]
18-
public ?string $path = null;
19-
20-
#[Serializer\Groups(["web_response"])]
21-
public ?PersistableInterface $item = null;
22-
23-
#[Serializer\Groups(["web_response"])]
24-
public ?BreadcrumbsInterface $breadcrumbs = null;
25-
26-
#[Serializer\Groups(["web_response"])]
27-
public ?NodesSourcesHeadInterface $head = null;
28-
/**
29-
* @var Collection<int, WalkerInterface>|null
30-
*/
31-
#[Serializer\Groups(["web_response"])]
32-
private ?Collection $blocks = null;
33-
/**
34-
* @var array<RealmInterface>|null
35-
*/
36-
#[Serializer\Groups(["web_response"])]
37-
private ?array $realms = null;
38-
39-
#[Serializer\Groups(["web_response"])]
40-
private bool $hidingBlocks = false;
41-
42-
/**
43-
* @return PersistableInterface|null
44-
*/
45-
public function getItem(): ?PersistableInterface
46-
{
47-
return $this->item;
48-
}
49-
50-
/**
51-
* @return Collection<int, WalkerInterface>|null
52-
*/
53-
public function getBlocks(): ?Collection
54-
{
55-
return $this->blocks;
56-
}
57-
58-
/**
59-
* @param Collection<int, WalkerInterface>|null $blocks
60-
* @return WebResponse
61-
*/
62-
public function setBlocks(?Collection $blocks): WebResponse
63-
{
64-
$this->blocks = $blocks;
65-
return $this;
66-
}
67-
68-
/**
69-
* @return RealmInterface[]|null
70-
*/
71-
public function getRealms(): ?array
72-
{
73-
return $this->realms;
74-
}
75-
76-
/**
77-
* @param RealmInterface[]|null $realms
78-
* @return WebResponse
79-
*/
80-
public function setRealms(?array $realms): WebResponse
81-
{
82-
$this->realms = $realms;
83-
return $this;
84-
}
85-
86-
/**
87-
* @return bool
88-
*/
89-
public function isHidingBlocks(): bool
90-
{
91-
return $this->hidingBlocks;
92-
}
93-
94-
/**
95-
* @param bool $hidingBlocks
96-
* @return WebResponse
97-
*/
98-
public function setHidingBlocks(bool $hidingBlocks): WebResponse
99-
{
100-
$this->hidingBlocks = $hidingBlocks;
101-
return $this;
102-
}
9+
use WebResponseTrait;
10310
}

0 commit comments

Comments
 (0)