Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Make the query collection provider configurable #76

Merged
merged 4 commits into from
Jun 23, 2014

Conversation

veewee
Copy link
Contributor

@veewee veewee commented Apr 17, 2014

(Note: To prevent merge conflicts, check merge order in #79 )

This PR will fix issue #75
It will make it is possible to add new query objects. When no query object is provided, there will be a fallback to the default ODM and ORM query objects.

Example:

Config:

    'zf-collection-query' => array(
        'invokables' => array(
            'custom-query-provider' => 'Application\My\Custom\Query',
        )
    ),
    'zf-apigility' => array(
        'doctrine-connected' => array(
            'Api\\V1\\Rest\\Users\\UserResource' => array(
                'object_manager' => 'doctrine.documentmanager.odm_default',
                'hydrator' => 'TenantApi\\V1\\Rest\\Users\\UsersHydrator',
                'query_provider' => 'custom-query-provider',
            ),
        ),
    ),

Class:

namespace Application\My\Custom;
use ZF\Apigility\Doctrine\Server\Collection\Query\FetchAllOdmQuery;
class Query extends FetchAllOdmQuery
{
    public function createQuery($entityClass, array $parameters)
    {
        $queryBuilder = parent::createQuery($entityClass, $parameters);
        $queryBuilder->andWhere($queryBuilder->expr()->field('field')->notEqual('value'));
        return $queryBuilder
    }

}

Notes:

  • No unit tests added. At the moment only end-to-end tests exist. Shouldn't there also be spec tests?
  • The getHydrator in the DoctrineResource could also be injected through the factory. This will make the DoctrineResource code cleaner.

*/
protected function loadQueryProvider(ServiceLocatorInterface $serviceLocator, $config, $objectManager)
{
$queryManager = $serviceLocator->get('ZfOdmCollectionQueryManager');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ZfOdmCollectionQueryManager is not specific to Odm and that namepiece should be dropped from the service name.

@veewee
Copy link
Contributor Author

veewee commented Apr 17, 2014

@TomHAnderson Fixed the comments.

@TomHAnderson
Copy link
Contributor

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants