diff --git a/config/dependencies.yaml b/config/dependencies.yaml index 70ab6cd09..31923375d 100644 --- a/config/dependencies.yaml +++ b/config/dependencies.yaml @@ -11,11 +11,11 @@ services: public: true tags: [ 'controller.service_arguments' ] - Pimcore\Bundle\StudioBackendBundle\Dependency\RepositoryInterface: - class: Pimcore\Bundle\StudioBackendBundle\Dependency\Repository + Pimcore\Bundle\StudioBackendBundle\Dependency\Repository\DependencyRepositoryInterface: + class: Pimcore\Bundle\StudioBackendBundle\Dependency\Repository\DependencyRepository - Pimcore\Bundle\StudioBackendBundle\Dependency\Service\DependencyHydratorServiceInterface: - class: Pimcore\Bundle\StudioBackendBundle\Dependency\Service\DependencyHydratorService + Pimcore\Bundle\StudioBackendBundle\Dependency\Service\DependencyServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Dependency\Service\DependencyService Pimcore\Bundle\StudioBackendBundle\Dependency\Hydrator\DependencyHydratorInterface: class: Pimcore\Bundle\StudioBackendBundle\Dependency\Hydrator\DependencyHydrator \ No newline at end of file diff --git a/src/OpenApi/Attributes/Parameters/Query/DependencyModeParameter.php b/src/Dependency/Attributes/Parameters/Query/DependencyModeParameter.php similarity index 88% rename from src/OpenApi/Attributes/Parameters/Query/DependencyModeParameter.php rename to src/Dependency/Attributes/Parameters/Query/DependencyModeParameter.php index 9510794ba..20055dd9c 100644 --- a/src/OpenApi/Attributes/Parameters/Query/DependencyModeParameter.php +++ b/src/Dependency/Attributes/Parameters/Query/DependencyModeParameter.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query; +namespace Pimcore\Bundle\StudioBackendBundle\Dependency\Attributes\Parameters\Query; use Attribute; use OpenApi\Attributes\QueryParameter; @@ -34,7 +34,7 @@ public function __construct( schema: new Schema( type: 'string', enum: DependencyMode::cases(), - example: null + example: DependencyMode::REQUIRED_BY->value ), ); } diff --git a/src/OpenApi/Attributes/Response/Property/DependencyCollection.php b/src/Dependency/Attributes/Response/Property/DependencyCollection.php similarity index 80% rename from src/OpenApi/Attributes/Response/Property/DependencyCollection.php rename to src/Dependency/Attributes/Response/Property/DependencyCollection.php index 75cd33d4a..fa7606031 100644 --- a/src/OpenApi/Attributes/Response/Property/DependencyCollection.php +++ b/src/Dependency/Attributes/Response/Property/DependencyCollection.php @@ -14,12 +14,12 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Property; +namespace Pimcore\Bundle\StudioBackendBundle\Dependency\Attributes\Response\Property; use OpenApi\Attributes\Items; use OpenApi\Attributes\Property; use OpenApi\Attributes\Schema; -use Pimcore\Bundle\StudioBackendBundle\Version\Schema\Version; +use Pimcore\Bundle\StudioBackendBundle\Dependency\Schema\Dependency; /** * @internal @@ -34,7 +34,7 @@ public function __construct() type: 'array', items: new Items( anyOf: [ - new Schema(ref: Version::class), + new Schema(ref: Dependency::class), ] ) ); diff --git a/src/Dependency/Controller/CollectionController.php b/src/Dependency/Controller/CollectionController.php index 62a682778..d05b3b59a 100644 --- a/src/Dependency/Controller/CollectionController.php +++ b/src/Dependency/Controller/CollectionController.php @@ -18,9 +18,10 @@ use OpenApi\Attributes\Get; use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; +use Pimcore\Bundle\StudioBackendBundle\Dependency\Attributes\Parameters\Query\DependencyModeParameter; +use Pimcore\Bundle\StudioBackendBundle\Dependency\Attributes\Response\Property\DependencyCollection; use Pimcore\Bundle\StudioBackendBundle\Dependency\Request\DependencyParameters; -use Pimcore\Bundle\StudioBackendBundle\Dependency\Service\DependencyHydratorServiceInterface; -use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\DependencyModeParameter; +use Pimcore\Bundle\StudioBackendBundle\Dependency\Service\DependencyServiceInterface; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\ElementTypeParameter; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\IdParameter; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Query\PageParameter; @@ -31,7 +32,6 @@ use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\NotFoundResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnauthorizedResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Error\UnprocessableContentResponse; -use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Property\DependencyCollection; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface; @@ -51,14 +51,14 @@ final class CollectionController extends AbstractApiController public function __construct( SerializerInterface $serializer, private readonly SecurityServiceInterface $securityService, - private readonly DependencyHydratorServiceInterface $hydratorService, + private readonly DependencyServiceInterface $hydratorService, ) { parent::__construct($serializer); } #[Route('/dependencies', name: 'pimcore_studio_api_dependencies', methods: ['GET'])] //#[IsGranted('STUDIO_API')] - #[GET( + #[Get( path: self::API_PATH . '/dependencies', operationId: 'getDependencies', description: 'Get paginated dependencies. @@ -84,7 +84,7 @@ public function __construct( #[UnprocessableContentResponse] public function getDependencies(#[MapQueryString] DependencyParameters $parameters): JsonResponse { - $result = $this->hydratorService->getHydratedDependencies( + $result = $this->hydratorService->getDependencies( $parameters, $this->securityService->getCurrentUser() ); diff --git a/src/Dependency/Event/DependencyEvent.php b/src/Dependency/Event/DependencyEvent.php new file mode 100644 index 000000000..848efc217 --- /dev/null +++ b/src/Dependency/Event/DependencyEvent.php @@ -0,0 +1,40 @@ +dependency; + } +} diff --git a/src/Dependency/Repository.php b/src/Dependency/Repository/DependencyRepository.php similarity index 93% rename from src/Dependency/Repository.php rename to src/Dependency/Repository/DependencyRepository.php index 62e35ebb7..79c193b0f 100644 --- a/src/Dependency/Repository.php +++ b/src/Dependency/Repository/DependencyRepository.php @@ -14,7 +14,7 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Dependency; +namespace Pimcore\Bundle\StudioBackendBundle\Dependency\Repository; use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface; use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait; @@ -22,7 +22,7 @@ /** * @internal */ -final readonly class Repository implements RepositoryInterface +final readonly class DependencyRepository implements DependencyRepositoryInterface { use ElementProviderTrait; diff --git a/src/Dependency/RepositoryInterface.php b/src/Dependency/Repository/DependencyRepositoryInterface.php similarity index 88% rename from src/Dependency/RepositoryInterface.php rename to src/Dependency/Repository/DependencyRepositoryInterface.php index 6039d34d3..7c07c527c 100644 --- a/src/Dependency/RepositoryInterface.php +++ b/src/Dependency/Repository/DependencyRepositoryInterface.php @@ -14,12 +14,12 @@ * @license http://www.pimcore.org/license GPLv3 and PCL */ -namespace Pimcore\Bundle\StudioBackendBundle\Dependency; +namespace Pimcore\Bundle\StudioBackendBundle\Dependency\Repository; /** * @internal */ -interface RepositoryInterface +interface DependencyRepositoryInterface { public function listRequiresDependencies(string $elementType, int $elementId): array; diff --git a/src/Dependency/Result/ListingResult.php b/src/Dependency/Result/Collection.php similarity index 97% rename from src/Dependency/Result/ListingResult.php rename to src/Dependency/Result/Collection.php index 06e5b8252..880aa6a55 100644 --- a/src/Dependency/Result/ListingResult.php +++ b/src/Dependency/Result/Collection.php @@ -19,7 +19,7 @@ /** * @internal */ -final readonly class ListingResult +final readonly class Collection { /** * @param array $items diff --git a/src/Dependency/Schema/Dependency.php b/src/Dependency/Schema/Dependency.php index 8e66b81c1..19defab67 100644 --- a/src/Dependency/Schema/Dependency.php +++ b/src/Dependency/Schema/Dependency.php @@ -18,24 +18,28 @@ use OpenApi\Attributes\Property; use OpenApi\Attributes\Schema; +use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface; +use Pimcore\Bundle\StudioBackendBundle\Util\Traits\AdditionalAttributesTrait; #[Schema( title: 'Dependency', type: 'object' )] -final readonly class Dependency +final class Dependency implements AdditionalAttributesInterface { + use AdditionalAttributesTrait; + public function __construct( #[Property(description: 'id', type: 'int')] - private int $id, + private readonly int $id, #[Property(description: 'path', type: 'string', example: 'text')] - private string $path, + private readonly string $path, #[Property(description: 'type', type: 'string', example: 'asset')] - private string $type, + private readonly string $type, #[Property(description: 'subType', type: 'string', example: 'image')] - private string $subType, + private readonly string $subType, #[Property(description: 'published', type: 'bool', example: 'true')] - private bool $published, + private readonly bool $published, ) { } diff --git a/src/Dependency/Service/DependencyHydratorService.php b/src/Dependency/Service/DependencyService.php similarity index 52% rename from src/Dependency/Service/DependencyHydratorService.php rename to src/Dependency/Service/DependencyService.php index 73c1b28be..8d6ba0a56 100644 --- a/src/Dependency/Service/DependencyHydratorService.php +++ b/src/Dependency/Service/DependencyService.php @@ -16,84 +16,91 @@ namespace Pimcore\Bundle\StudioBackendBundle\Dependency\Service; +use Pimcore\Bundle\StudioBackendBundle\Dependency\Event\DependencyEvent; use Pimcore\Bundle\StudioBackendBundle\Dependency\Hydrator\DependencyHydratorInterface; -use Pimcore\Bundle\StudioBackendBundle\Dependency\RepositoryInterface; +use Pimcore\Bundle\StudioBackendBundle\Dependency\Repository\DependencyRepositoryInterface; use Pimcore\Bundle\StudioBackendBundle\Dependency\Request\DependencyParameters; +use Pimcore\Bundle\StudioBackendBundle\Dependency\Result\Collection; use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait; -use Pimcore\Bundle\StudioBackendBundle\Dependency\Result\ListingResult; use Pimcore\Model\UserInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; -final readonly class DependencyHydratorService implements DependencyHydratorServiceInterface +final readonly class DependencyService implements DependencyServiceInterface { use ElementProviderTrait; public function __construct( - private RepositoryInterface $repository, + private DependencyRepositoryInterface $dependencyRepository, private DependencyHydratorInterface $dependencyHydrator, + private EventDispatcherInterface $eventDispatcher, ) { } - public function getHydratedDependencies( + public function getDependencies( DependencyParameters $parameters, UserInterface $user - ): ListingResult + ): Collection { return match ($parameters->getMode()) { - DependencyMode::REQUIRES => $this->getHydratedRequiredDependencies($parameters), - DependencyMode::REQUIRED_BY => $this->getHydratedRequiredByDependencies($parameters), + DependencyMode::REQUIRES => $this->getRequiredDependencies($parameters), + DependencyMode::REQUIRED_BY => $this->getRequiredByDependencies($parameters), }; } - private function hydrateDependencyCollection(array $dependencies): array + private function getDependencyCollection(array $dependencies): array { $hydratedDependencies = []; foreach($dependencies as $dependency) { - $hydratedDependency = $this->dependencyHydrator->hydrate($dependency); - if($hydratedDependency) { - $hydratedDependencies[] = $hydratedDependency; + $dependency = $this->dependencyHydrator->hydrate($dependency); + if($dependency) { + $this->eventDispatcher->dispatch( + new DependencyEvent($dependency), + DependencyEvent::EVENT_NAME + ); + $hydratedDependencies[] = $dependency; } } return $hydratedDependencies; } - private function getHydratedRequiredDependencies( + private function getRequiredDependencies( DependencyParameters $parameters - ): ListingResult { + ): Collection { - $dependencies = $this->repository->listRequiresDependencies( + $dependencies = $this->dependencyRepository->listRequiresDependencies( $parameters->getElementType(), $parameters->getElementId() ); - $dependencies = $this->hydrateDependencyCollection($dependencies); + $dependencies = $this->getDependencyCollection($dependencies); - return new ListingResult( + return new Collection( $dependencies, $parameters->getPage(), $parameters->getPageSize(), - $this->repository->listRequiresDependenciesTotalCount( + $this->dependencyRepository->listRequiresDependenciesTotalCount( $parameters->getElementType(), $parameters->getElementId() ) ); } - private function getHydratedRequiredByDependencies( + private function getRequiredByDependencies( DependencyParameters $parameters - ): ListingResult { - $dependencies = $this->repository->listRequiredByDependencies( + ): Collection { + $dependencies = $this->dependencyRepository->listRequiredByDependencies( $parameters->getElementType(), $parameters->getElementId() ); - $dependencies = $this->hydrateDependencyCollection($dependencies); + $dependencies = $this->getDependencyCollection($dependencies); - return new ListingResult( + return new Collection( $dependencies, $parameters->getPage(), $parameters->getPageSize(), - $this->repository->listRequiredByDependenciesTotalCount( + $this->dependencyRepository->listRequiredByDependenciesTotalCount( $parameters->getElementType(), $parameters->getElementId() ) diff --git a/src/Dependency/Service/DependencyHydratorServiceInterface.php b/src/Dependency/Service/DependencyServiceInterface.php similarity index 79% rename from src/Dependency/Service/DependencyHydratorServiceInterface.php rename to src/Dependency/Service/DependencyServiceInterface.php index ac2039924..7f1e90644 100644 --- a/src/Dependency/Service/DependencyHydratorServiceInterface.php +++ b/src/Dependency/Service/DependencyServiceInterface.php @@ -17,13 +17,13 @@ namespace Pimcore\Bundle\StudioBackendBundle\Dependency\Service; use Pimcore\Bundle\StudioBackendBundle\Dependency\Request\DependencyParameters; -use Pimcore\Bundle\StudioBackendBundle\Dependency\Result\ListingResult; +use Pimcore\Bundle\StudioBackendBundle\Dependency\Result\Collection; use Pimcore\Model\UserInterface; -interface DependencyHydratorServiceInterface +interface DependencyServiceInterface { - public function getHydratedDependencies( + public function getDependencies( DependencyParameters $parameters, UserInterface $user - ): ListingResult; + ): Collection; } diff --git a/src/Property/Event/PredefinedPropertyEvent.php b/src/Property/Event/PredefinedPropertyEvent.php index 2a5d4a9d9..54a5e9b10 100644 --- a/src/Property/Event/PredefinedPropertyEvent.php +++ b/src/Property/Event/PredefinedPropertyEvent.php @@ -22,6 +22,7 @@ final class PredefinedPropertyEvent extends AbstractPreResponseEvent { public const EVENT_NAME = 'pre_response.predefined_property'; + public function __construct( private readonly PredefinedProperty $predefinedProperty ) diff --git a/src/Version/Hydrator/VersionHydratorService.php b/src/Version/Hydrator/VersionHydratorService.php index 22c7513f5..5b6614906 100644 --- a/src/Version/Hydrator/VersionHydratorService.php +++ b/src/Version/Hydrator/VersionHydratorService.php @@ -59,6 +59,7 @@ public function getHydratedVersions( $versionObjects = $list->load(); foreach ($versionObjects as $versionObject) { $versions[] = $this->versionHydrator->hydrate($versionObject, $scheduledTasks); + } return new ListingResult(