Skip to content

Commit

Permalink
apply review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmzig committed Nov 29, 2024
1 parent 27234fe commit a117ac9
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 13 deletions.
10 changes: 9 additions & 1 deletion config/documents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ services:
#

Pimcore\Bundle\StudioBackendBundle\Document\Repository\SiteRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Document\Repository\SiteRepository
class: Pimcore\Bundle\StudioBackendBundle\Document\Repository\SiteRepository


#
# Hydrators
#

Pimcore\Bundle\StudioBackendBundle\Document\Hydrator\SiteHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Document\Hydrator\SiteHydrator
10 changes: 5 additions & 5 deletions src/Class/Service/FieldCollection/LayoutDefinitionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\DataObjectResolverInterface;
use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\FieldCollection\DefinitionResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Class\Event\FieldCollection\LayoutDefinitionEvent;
use Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\LayoutDefinitionHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\SiteHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\Class\Schema\LayoutDefinition;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Model\DataObject;
Expand All @@ -34,11 +34,11 @@
final class LayoutDefinitionService implements LayoutDefinitionServiceInterface
{
public function __construct(
private readonly DataObjectResolverInterface $dataObjectResolver,
private readonly DataObjectResolverInterface $dataObjectResolver,
private readonly ClassDefinitionResolverInterface $classDefinitionResolver,
private readonly DefinitionResolverInterface $definitionResolver,
private readonly LayoutDefinitionHydratorInterface $layoutDefinitionHydrator,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly DefinitionResolverInterface $definitionResolver,
private readonly SiteHydratorInterface $layoutDefinitionHydrator,

Check failure on line 40 in src/Class/Service/FieldCollection/LayoutDefinitionService.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, 11.x-dev as 11.99.9, true) / Static analysis with phpstan

Parameter $layoutDefinitionHydrator of method Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\LayoutDefinitionService::__construct() has invalid type Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\SiteHydratorInterface.

Check failure on line 40 in src/Class/Service/FieldCollection/LayoutDefinitionService.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, 11.x-dev as 11.99.9, true) / Static analysis with phpstan

Property Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\LayoutDefinitionService::$layoutDefinitionHydrator has unknown class Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\SiteHydratorInterface as its type.

Check failure on line 40 in src/Class/Service/FieldCollection/LayoutDefinitionService.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.2, lowest, false) / Static analysis with phpstan

Parameter $layoutDefinitionHydrator of method Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\LayoutDefinitionService::__construct() has invalid type Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\SiteHydratorInterface.

Check failure on line 40 in src/Class/Service/FieldCollection/LayoutDefinitionService.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.2, lowest, false) / Static analysis with phpstan

Property Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\LayoutDefinitionService::$layoutDefinitionHydrator has unknown class Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\SiteHydratorInterface as its type.

Check failure on line 40 in src/Class/Service/FieldCollection/LayoutDefinitionService.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, false) / Static analysis with phpstan

Parameter $layoutDefinitionHydrator of method Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\LayoutDefinitionService::__construct() has invalid type Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\SiteHydratorInterface.

Check failure on line 40 in src/Class/Service/FieldCollection/LayoutDefinitionService.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, false) / Static analysis with phpstan

Property Pimcore\Bundle\StudioBackendBundle\Class\Service\FieldCollection\LayoutDefinitionService::$layoutDefinitionHydrator has unknown class Pimcore\Bundle\StudioBackendBundle\Class\Hydrator\FieldCollection\SiteHydratorInterface as its type.
private readonly EventDispatcherInterface $eventDispatcher,
) {
}

Expand Down
37 changes: 37 additions & 0 deletions src/Document/Hydrator/SiteHydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Document\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Site;
use Pimcore\Model\Site as SiteModel;

/**
* @internal
*/
final class SiteHydrator implements SiteHydratorInterface
{
public function hydrate(SiteModel $siteModel): Site
{
return new Site(
$siteModel->getId(),
$siteModel->getDomains(),
$siteModel->getMainDomain(),
$siteModel->getRootId(),
$siteModel->getRootPath(),
);
}
}
28 changes: 28 additions & 0 deletions src/Document/Hydrator/SiteHydratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Document\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Site;
use Pimcore\Model\Site as SiteModel;

/**
* @internal
*/
interface SiteHydratorInterface
{
public function hydrate(SiteModel $siteModel): Site;
}
3 changes: 3 additions & 0 deletions src/Document/Schema/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
schema: 'Site',
title: 'Site',
required: [
'id',
'domains',
'domain',
],
type: 'object'
)]
Expand Down
10 changes: 3 additions & 7 deletions src/Document/Service/SiteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Pimcore\Bundle\StudioBackendBundle\Document\Service;

use Pimcore\Bundle\StudioBackendBundle\Document\Event\PreResponse\SiteEvent;
use Pimcore\Bundle\StudioBackendBundle\Document\Hydrator\SiteHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\Document\MappedParameter\ExcludeMainSiteParameter;
use Pimcore\Bundle\StudioBackendBundle\Document\Repository\SiteRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\Document\Schema\Site;
Expand All @@ -32,6 +33,7 @@

public function __construct(
private EventDispatcherInterface $eventDispatcher,
private SiteHydratorInterface $siteHydrator,
private SiteRepositoryInterface $siteRepository,
) {
}
Expand All @@ -48,13 +50,7 @@ public function getAvailableSites(ExcludeMainSiteParameter $parameter): array

$siteList = $this->siteRepository->listSites();
foreach ($siteList as $siteEntry) {
$site = new Site(
$siteEntry->getId(),
$siteEntry->getDomains(),
$siteEntry->getMainDomain(),
$siteEntry->getRootId(),
$siteEntry->getRootPath(),
);
$site = $this->siteHydrator->hydrate($siteEntry);

$this->eventDispatcher->dispatch(new SiteEvent($site), SiteEvent::EVENT_NAME);
$sites[] = $site;
Expand Down

0 comments on commit a117ac9

Please sign in to comment.