/**
* Fetch a resource
*
* If the extractCollections array contains a collection for this resource
* expand that collection instead of returning a link to the collection
*
* @param mixed $id
* @return ApiProblem|mixed
*/
public function fetch($id)
{
$event = new DoctrineResourceEvent(DoctrineResourceEvent::EVENT_FETCH_PRE, $this);
$event->setEntityClassName($this->getEntityClass());
$event->setEntityId($id);
$eventManager = $this->getEventManager();
$response = $eventManager->trigger($event);
if ($response->last() instanceof ApiProblem) {
return $response->last();
}
$entity = $this->findEntity($id, 'fetch');
if ($entity instanceof ApiProblem) {
// @codeCoverageIgnoreStart
return $entity;
}
// @codeCoverageIgnoreEnd
$results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_FETCH_POST, $entity);
if ($results->last() instanceof ApiProblem) {
return $results->last();
}
return $entity;
}