I am using Zend Expressive Hal to generate a Hal Response. The problem is that when I use the same resource_class for 2 routes in Hal metadata, it throws an exception and does not work. I was wondering if there is a way where I can use the same object for more than one route. Here is my Hal metadata code:
return [
MetadataMap::class => [
[
'__class__' => RouteBasedResourceMetadata::class,
'resource_class' => ImmutablePropertyObject::class,
'route' => 'api.ping',
'extractor' => ArraySerializableHydrator::class,
],
[
'__class__' => RouteBasedResourceMetadata::class,
'resource_class' => \Abstracts\PropertyObject::class,
'route' => 'api.getEventById',
'extractor' => \Event\EventHydrator::class,
],
[
'__class__' => RouteBasedResourceMetadata::class,
'resource_class' => \Abstracts\PropertyObject::class,
'route' => 'api.postEvent',
'extractor' => \Event\EventHydrator::class,
]
]
];
Here are my routes:
return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void {
$app->get('/', App\Handler\HomePageHandler::class, 'home');
$app->get('/api/ping', App\Handler\PingHandler::class, 'api.ping');
$app->get('/api/event/:id', Event\Handler\EventReadHandler::class, 'api.getEventById');
$app->post('/api/event', Event\Handler\EventPostHandler::class, 'api.postEvent');
$app->put('/api/event', Event\Handler\EventUpdateHandler::class, 'api.updateEvent');
};