Skip to content

Commit

Permalink
feat: Better overridability for WebResponses
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Feb 8, 2024
1 parent b4f6863 commit 1dff926
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,15 @@ class WebResponseOutputDataTransformer implements WebResponseDataTransformerInte
use BlocksAwareWebResponseOutputDataTransformerTrait;
use RealmsAwareWebResponseOutputDataTransformerTrait;

private NodesSourcesHeadFactoryInterface $nodesSourcesHeadFactory;
private BreadcrumbsFactoryInterface $breadcrumbsFactory;
private WalkerContextInterface $walkerContext;
private CacheItemPoolInterface $cacheItemPool;
private UrlGeneratorInterface $urlGenerator;
private RealmResolverInterface $realmResolver;
private TreeWalkerGenerator $treeWalkerGenerator;

public function __construct(
NodesSourcesHeadFactoryInterface $nodesSourcesHeadFactory,
BreadcrumbsFactoryInterface $breadcrumbsFactory,
WalkerContextInterface $walkerContext,
CacheItemPoolInterface $cacheItemPool,
UrlGeneratorInterface $urlGenerator,
RealmResolverInterface $realmResolver,
TreeWalkerGenerator $treeWalkerGenerator
protected readonly NodesSourcesHeadFactoryInterface $nodesSourcesHeadFactory,
protected readonly BreadcrumbsFactoryInterface $breadcrumbsFactory,
protected readonly WalkerContextInterface $walkerContext,
protected readonly CacheItemPoolInterface $cacheItemPool,
protected readonly UrlGeneratorInterface $urlGenerator,
protected readonly RealmResolverInterface $realmResolver,
protected readonly TreeWalkerGenerator $treeWalkerGenerator
) {
$this->nodesSourcesHeadFactory = $nodesSourcesHeadFactory;
$this->breadcrumbsFactory = $breadcrumbsFactory;
$this->walkerContext = $walkerContext;
$this->cacheItemPool = $cacheItemPool;
$this->urlGenerator = $urlGenerator;
$this->realmResolver = $realmResolver;
$this->treeWalkerGenerator = $treeWalkerGenerator;
}

protected function getWalkerContext(): WalkerContextInterface
Expand Down
23 changes: 4 additions & 19 deletions lib/RoadizCoreBundle/src/Api/Model/NodesSourcesHeadFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,12 @@

final class NodesSourcesHeadFactory implements NodesSourcesHeadFactoryInterface
{
private Settings $settingsBag;
private UrlGeneratorInterface $urlGenerator;
private NodeSourceApi $nodeSourceApi;
private HandlerFactoryInterface $handlerFactory;

/**
* @param Settings $settingsBag
* @param UrlGeneratorInterface $urlGenerator
* @param NodeSourceApi $nodeSourceApi
* @param HandlerFactoryInterface $handlerFactory
*/
public function __construct(
Settings $settingsBag,
UrlGeneratorInterface $urlGenerator,
NodeSourceApi $nodeSourceApi,
HandlerFactoryInterface $handlerFactory
private readonly Settings $settingsBag,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly NodeSourceApi $nodeSourceApi,
private readonly HandlerFactoryInterface $handlerFactory
) {
$this->settingsBag = $settingsBag;
$this->urlGenerator = $urlGenerator;
$this->nodeSourceApi = $nodeSourceApi;
$this->handlerFactory = $handlerFactory;
}

public function createForNodeSource(NodesSources $nodesSources): NodesSourcesHeadInterface
Expand Down
95 changes: 1 addition & 94 deletions lib/RoadizCoreBundle/src/Api/Model/WebResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,100 +4,7 @@

namespace RZ\Roadiz\CoreBundle\Api\Model;

use ApiPlatform\Metadata\ApiProperty;
use Doctrine\Common\Collections\Collection;
use RZ\Roadiz\Core\AbstractEntities\PersistableInterface;
use RZ\Roadiz\CoreBundle\Api\Breadcrumbs\BreadcrumbsInterface;
use RZ\Roadiz\CoreBundle\Model\RealmInterface;
use RZ\TreeWalker\WalkerInterface;
use Symfony\Component\Serializer\Annotation as Serializer;

final class WebResponse implements WebResponseInterface, BlocksAwareWebResponseInterface, RealmsAwareWebResponseInterface
{
#[ApiProperty(identifier: true)]
public ?string $path = null;

#[Serializer\Groups(["web_response"])]
public ?PersistableInterface $item = null;

#[Serializer\Groups(["web_response"])]
public ?BreadcrumbsInterface $breadcrumbs = null;

#[Serializer\Groups(["web_response"])]
public ?NodesSourcesHeadInterface $head = null;
/**
* @var Collection<int, WalkerInterface>|null
*/
#[Serializer\Groups(["web_response"])]
private ?Collection $blocks = null;
/**
* @var array<RealmInterface>|null
*/
#[Serializer\Groups(["web_response"])]
private ?array $realms = null;

#[Serializer\Groups(["web_response"])]
private bool $hidingBlocks = false;

/**
* @return PersistableInterface|null
*/
public function getItem(): ?PersistableInterface
{
return $this->item;
}

/**
* @return Collection<int, WalkerInterface>|null
*/
public function getBlocks(): ?Collection
{
return $this->blocks;
}

/**
* @param Collection<int, WalkerInterface>|null $blocks
* @return WebResponse
*/
public function setBlocks(?Collection $blocks): WebResponse
{
$this->blocks = $blocks;
return $this;
}

/**
* @return RealmInterface[]|null
*/
public function getRealms(): ?array
{
return $this->realms;
}

/**
* @param RealmInterface[]|null $realms
* @return WebResponse
*/
public function setRealms(?array $realms): WebResponse
{
$this->realms = $realms;
return $this;
}

/**
* @return bool
*/
public function isHidingBlocks(): bool
{
return $this->hidingBlocks;
}

/**
* @param bool $hidingBlocks
* @return WebResponse
*/
public function setHidingBlocks(bool $hidingBlocks): WebResponse
{
$this->hidingBlocks = $hidingBlocks;
return $this;
}
use WebResponseTrait;
}
103 changes: 103 additions & 0 deletions lib/RoadizCoreBundle/src/Api/Model/WebResponseTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\CoreBundle\Api\Model;

use ApiPlatform\Metadata\ApiProperty;
use Doctrine\Common\Collections\Collection;
use RZ\Roadiz\Core\AbstractEntities\PersistableInterface;
use RZ\Roadiz\CoreBundle\Api\Breadcrumbs\BreadcrumbsInterface;
use RZ\Roadiz\CoreBundle\Model\RealmInterface;
use RZ\TreeWalker\WalkerInterface;
use Symfony\Component\Serializer\Annotation as Serializer;

trait WebResponseTrait
{
#[ApiProperty(identifier: true)]
public ?string $path = null;

#[Serializer\Groups(["web_response"])]
public ?PersistableInterface $item = null;

#[Serializer\Groups(["web_response"])]
public ?BreadcrumbsInterface $breadcrumbs = null;

#[Serializer\Groups(["web_response"])]
public ?NodesSourcesHeadInterface $head = null;
/**
* @var Collection<int, WalkerInterface>|null
*/
#[Serializer\Groups(["web_response"])]
private ?Collection $blocks = null;
/**
* @var array<RealmInterface>|null
*/
#[Serializer\Groups(["web_response"])]
private ?array $realms = null;

#[Serializer\Groups(["web_response"])]
private bool $hidingBlocks = false;

/**
* @return PersistableInterface|null
*/
public function getItem(): ?PersistableInterface
{
return $this->item;
}

/**
* @return Collection<int, WalkerInterface>|null
*/
public function getBlocks(): ?Collection
{
return $this->blocks;
}

/**
* @param Collection<int, WalkerInterface>|null $blocks
* @return $this
*/
public function setBlocks(?Collection $blocks): self
{
$this->blocks = $blocks;
return $this;
}

/**
* @return RealmInterface[]|null
*/
public function getRealms(): ?array
{
return $this->realms;
}

/**
* @param RealmInterface[]|null $realms
* @return $this
*/
public function setRealms(?array $realms): self
{
$this->realms = $realms;
return $this;
}

/**
* @return bool
*/
public function isHidingBlocks(): bool
{
return $this->hidingBlocks;
}

/**
* @param bool $hidingBlocks
* @return $this
*/
public function setHidingBlocks(bool $hidingBlocks): self
{
$this->hidingBlocks = $hidingBlocks;
return $this;
}
}

0 comments on commit 1dff926

Please sign in to comment.