ZF\Apigility\Doctrine\Server\Resource\DoctrineResource::fetch PHP Method

fetch() public method

If the extractCollections array contains a collection for this resource expand that collection instead of returning a link to the collection
public fetch ( mixed $id ) : ZF\ApiProblem\ApiProblem | mixed
$id mixed
return ZF\ApiProblem\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->triggerEvent($event);
        if ($response->last() instanceof ApiProblem) {
            return $response->last();
        }
        $entity = $this->findEntity($id, 'fetch');
        if ($entity instanceof ApiProblem) {
            return $entity;
        }
        $results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_FETCH_POST, $entity);
        if ($results->last() instanceof ApiProblem) {
            return $results->last();
        }
        return $entity;
    }

Usage Example

Example #1
0
 /**
  * Fetch a user2note
  *
  * @param int $noteId
  * @throws \InvalidArgumentException
  * @return ApiProblem|mixed
  */
 public function fetch($noteId)
 {
     /** @var Service\User $userService */
     $userService = $this->getServiceManager()->get('user-service');
     $user = $userService->getUserByMail($this->getIdentity()->getName());
     $this->setEntityIdentifierName('userId.noteId');
     return parent::fetch($user->getId() . '.' . $noteId);
 }