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

fetchAll() public method

Fetch all or a subset of resources
public fetchAll ( array $data = [] ) : ZF\ApiProblem\ApiProblem | mixed
$data array
return ZF\ApiProblem\ApiProblem | mixed
    public function fetchAll($data = [])
    {
        // Build query
        $queryProvider = $this->getQueryProvider('fetch_all');
        $queryBuilder = $queryProvider->createQuery($this->getEvent(), $this->getEntityClass(), $data);
        if ($queryBuilder instanceof ApiProblem) {
            return $queryBuilder;
        }
        $response = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_FETCH_ALL_PRE, $this->getEntityClass(), $data);
        if ($response->last() instanceof ApiProblem) {
            return $response->last();
        }
        $adapter = $queryProvider->getPaginatedQuery($queryBuilder);
        $reflection = new ReflectionClass($this->getCollectionClass());
        $collection = $reflection->newInstance($adapter);
        $results = $this->triggerDoctrineEvent(DoctrineResourceEvent::EVENT_FETCH_ALL_POST, $this->getEntityClass(), $data);
        if ($results->last() instanceof ApiProblem) {
            return $results->last();
        }
        // Add event to set extra HAL data
        $entityClass = $this->getEntityClass();
        $this->getSharedEventManager()->attach(RestController::class, 'getList.post', function (EventInterface $e) use($queryProvider, $entityClass, $data) {
            /** @var \ZF\Hal\Collection $halCollection */
            $halCollection = $e->getParam('collection');
            $collection = $halCollection->getCollection();
            $collection->setItemCountPerPage($halCollection->getPageSize());
            $collection->setCurrentPageNumber($halCollection->getPage());
            $halCollection->setCollectionRouteOptions(['query' => $e->getTarget()->getRequest()->getQuery()->toArray()]);
        });
        return $collection;
    }