src/Server/Resource/DoctrineResource.php
/**
     * Fetch all or a subset of resources
     *
     * @param array $data
     * @return ApiProblem|mixed
     */
Fetch all or a subset of resources
@param array $data
@return ApiProblem|mixed
Fetch all or a subset of resources @param array $data @return ApiProblem|mixed
public function fetchAll($data = [])
    {
        $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();
        }
        $entityClass = $this->getEntityClass();
        $this->getSharedEventManager()->attach(
            RestController::class,
            'getList.post',
            function (EventInterface $e) use ($queryProvider, $entityClass, $data) {
                $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;
    }
public function fetchAll ( $ data = [ ] ) { $ 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 ( ) ; } $ entityClass = $ this -> getEntityClass ( ) ; $ this -> getSharedEventManager ( ) -> attach ( RestController :: class , 'getList.post' , function ( EventInterface $ e ) use ( $ queryProvider , $ entityClass , $ data ) { $ 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 ; }
Fetch all or a subset of resources
 @param array $data
 @return ApiProblem|mixed
Fetch all or a subset of resources @param array $data @return ApiProblem|mixed
// Build query // Add event to set extra HAL data /** @var \ZF\Hal\Collection $halCollection */