diff --git a/src/Event/LocalDataAwareEvent.php b/src/LocalData/LocalDataAwareEvent.php similarity index 93% rename from src/Event/LocalDataAwareEvent.php rename to src/LocalData/LocalDataAwareEvent.php index 1b5b474525cfd33bf4ac82acb6591118f3cd42e1..3b13e38ddf362bf2c7c9137488d4e682a02b6ec4 100644 --- a/src/Event/LocalDataAwareEvent.php +++ b/src/LocalData/LocalDataAwareEvent.php @@ -2,11 +2,9 @@ declare(strict_types=1); -namespace Dbp\Relay\CoreBundle\Event; +namespace Dbp\Relay\CoreBundle\LocalData; -use Dbp\Relay\CoreBundle\Entity\LocalDataAwareInterface; use Dbp\Relay\CoreBundle\Exception\ApiError; -use Dbp\Relay\CoreBundle\Service\LocalDataAwareEventDispatcher; use Symfony\Contracts\EventDispatcher\Event; class LocalDataAwareEvent extends Event diff --git a/src/Service/LocalDataAwareEventDispatcher.php b/src/LocalData/LocalDataAwareEventDispatcher.php similarity index 90% rename from src/Service/LocalDataAwareEventDispatcher.php rename to src/LocalData/LocalDataAwareEventDispatcher.php index c4077d5391dc9d3dbd39156bee977ee9d6d0a91a..9882d20bbcd3b6a1f0845dcb1df3592bf6883043 100644 --- a/src/Service/LocalDataAwareEventDispatcher.php +++ b/src/LocalData/LocalDataAwareEventDispatcher.php @@ -2,11 +2,10 @@ declare(strict_types=1); -namespace Dbp\Relay\CoreBundle\Service; +namespace Dbp\Relay\CoreBundle\LocalData; use ApiPlatform\Core\Exception\ResourceClassNotFoundException; use ApiPlatform\Core\Metadata\Resource\Factory\AnnotationResourceMetadataFactory; -use Dbp\Relay\CoreBundle\Event\LocalDataAwareEvent; use Dbp\Relay\CoreBundle\Exception\ApiError; use Doctrine\Common\Annotations\AnnotationReader; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -23,14 +22,10 @@ class LocalDataAwareEventDispatcher /** @var EventDispatcherInterface */ private $eventDispatcher; - /** @var string */ - private $eventName; - - public function __construct(string $resourceClass, EventDispatcherInterface $eventDispatcher, string $eventName) + public function __construct(string $resourceClass, EventDispatcherInterface $eventDispatcher) { $this->uniqueEntityName = self::getUniqueEntityName($resourceClass); $this->eventDispatcher = $eventDispatcher; - $this->eventName = $eventName; } /** @@ -65,11 +60,11 @@ class LocalDataAwareEventDispatcher /** * Dispatches the given event. */ - public function dispatch(LocalDataAwareEvent $event): void + public function dispatch(LocalDataAwareEvent $event, string $eventName): void { $event->setRequestedAttributes($this->requestedAttributes); - $this->eventDispatcher->dispatch($event, $this->eventName); + $this->eventDispatcher->dispatch($event, $eventName); $remainingLocalDataAttributes = $event->getRemainingRequestedAttributes(); if (!empty($remainingLocalDataAttributes)) { @@ -95,6 +90,8 @@ class LocalDataAwareEventDispatcher $uniqueName = $resourceMetadata->getShortName() ?? ''; if (empty($uniqueName)) { throw new ApiError(500, sprintf("'shortName' attribute missing in ApiResource annotation of resource class '%s'", $resourceClass)); + } elseif (str_contains($uniqueName, '.') || str_contains($uniqueName, ',')) { + throw new ApiError(500, sprintf("'shortName' attribute of resource class '%s' must not contain '.' or ',' characters: '%s'", $resourceClass, $uniqueName)); } return $uniqueName; diff --git a/src/Entity/LocalDataAwareInterface.php b/src/LocalData/LocalDataAwareInterface.php similarity index 92% rename from src/Entity/LocalDataAwareInterface.php rename to src/LocalData/LocalDataAwareInterface.php index 5fc64a25ddf98b9feb26fb995787fbfada095f57..891b7e473264799e56a42c05954c28e3da985922 100644 --- a/src/Entity/LocalDataAwareInterface.php +++ b/src/LocalData/LocalDataAwareInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Dbp\Relay\CoreBundle\Entity; +namespace Dbp\Relay\CoreBundle\LocalData; interface LocalDataAwareInterface { diff --git a/src/Entity/LocalDataAwareTrait.php b/src/LocalData/LocalDataAwareTrait.php similarity index 96% rename from src/Entity/LocalDataAwareTrait.php rename to src/LocalData/LocalDataAwareTrait.php index edf94aaa05cd00172ecf44fcbea560a245033a44..d6dfe8275d9b343f8776a4aad249c1844900dece 100644 --- a/src/Entity/LocalDataAwareTrait.php +++ b/src/LocalData/LocalDataAwareTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Dbp\Relay\CoreBundle\Entity; +namespace Dbp\Relay\CoreBundle\LocalData; use ApiPlatform\Core\Annotation\ApiProperty; use Symfony\Component\Serializer\Annotation\Groups;