Skip to content

Commit

Permalink
156 Integrated DataExtractor service into hydrator
Browse files Browse the repository at this point in the history
  • Loading branch information
mcop1 committed May 14, 2024
1 parent 0de7e38 commit d49098c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 78 deletions.
5 changes: 1 addition & 4 deletions config/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@ services:
class: Pimcore\Bundle\StudioBackendBundle\Dependency\Service\DependencyHydratorService

Pimcore\Bundle\StudioBackendBundle\Dependency\Hydrator\DependencyHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Dependency\Hydrator\DependencyHydrator

Pimcore\Bundle\StudioBackendBundle\Dependency\Extractor\DependencyDataExtractorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Dependency\Extractor\DependencyDataExtractor
class: Pimcore\Bundle\StudioBackendBundle\Dependency\Hydrator\DependencyHydrator
46 changes: 0 additions & 46 deletions src/Dependency/Extractor/DependencyDataExtractor.php

This file was deleted.

25 changes: 0 additions & 25 deletions src/Dependency/Extractor/DependencyDataExtractorInterface.php

This file was deleted.

23 changes: 20 additions & 3 deletions src/Dependency/Hydrator/DependencyHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@

namespace Pimcore\Bundle\StudioBackendBundle\Dependency\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\Dependency\Extractor\DependencyDataExtractorInterface;
use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Dependency\Schema\Dependency;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait;

/**
* @internal
*/
final readonly class DependencyHydrator implements DependencyHydratorInterface
{
use ElementProviderTrait;

public function __construct(
private DependencyDataExtractorInterface $dataExtractor
private ServiceResolverInterface $serviceResolver,
) {

}

public function hydrate(array $dependency): ?Dependency
Expand All @@ -38,7 +42,7 @@ public function hydrate(array $dependency): ?Dependency
return null;
}

$data = $this->dataExtractor->extractData($elementType, $elementId);
$data = $this->extractData($elementType, $elementId);

return new Dependency(
$data['id'],
Expand All @@ -48,4 +52,17 @@ public function hydrate(array $dependency): ?Dependency
$data['published']
);
}

private function extractData(string $elementType, int $elementId): array
{
$element = $this->getElement($this->serviceResolver, $elementType, $elementId);

return [
'id' => $element->getId(),
'type' => $this->serviceResolver->getElementType($element),
'subtype' => $element->getType(),
'published' => $this->serviceResolver->isPublished($element),
'path' => $element->getRealFullPath(),
];
}
}

0 comments on commit d49098c

Please sign in to comment.