Skip to content
Snippets Groups Projects
Commit d49b8519 authored by Tobias Gross-Vogt's avatar Tobias Gross-Vogt
Browse files

localdata files moved to LocalData dir/namespace, added check for valid shortName attribute

parent ad6f2efb
No related branches found
No related tags found
No related merge requests found
Pipeline #102695 passed
......@@ -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
......
......@@ -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;
......
......@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Dbp\Relay\CoreBundle\Entity;
namespace Dbp\Relay\CoreBundle\LocalData;
interface LocalDataAwareInterface
{
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment