Issue #2019651 by damiankloip: Add a QueryFactoryInterface for QueryFactory classes.

8.0.x
Alex Pott 2013-06-17 18:26:11 +02:00
parent 64a7739a52
commit 0204ee8e86
3 changed files with 65 additions and 29 deletions

View File

@ -10,13 +10,13 @@ namespace Drupal\Core\Config\Entity\Query;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\Query\QueryAggregateInterface;
use Drupal\Core\Entity\Query\QueryException;
use Drupal\Core\Entity\Query\QueryFactoryInterface;
/**
* Provides a factory for creating entity query objects for the config backend.
*/
class QueryFactory {
class QueryFactory implements QueryFactoryInterface {
/**
* The config storage used by the config entity query.
@ -32,41 +32,18 @@ class QueryFactory {
* The config storage used by the config entity query.
*/
public function __construct(StorageInterface $config_storage) {
return $this->configStorage = $config_storage;
$this->configStorage = $config_storage;
}
/**
* Instantiates an entity query for a given entity type.
*
* @param string $entity_type
* The entity type for the query.
* @param string $conjunction
* The operator to use to combine conditions: 'AND' or 'OR'.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager that handles the entity type.
*
* @return \Drupal\Core\Config\Entity\Query\Query
* An entity query for a specific configuration entity type.
* {@inheritdoc}
*/
public function get($entity_type, $conjunction, EntityManager $entity_manager) {
return new Query($entity_type, $conjunction, $entity_manager, $this->configStorage);
}
/**
* Returns a aggregation query object for a given entity type.
*
* @param string $entity_type
* The entity type.
* @param string $conjunction
* - AND: all of the conditions on the query need to match.
* - OR: at least one of the conditions on the query need to match.
*
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
*
* @throws \Drupal\Core\Entity\Query\QueryException
* @return \Drupal\Core\Entity\Query\QueryAggregateInterface
* The query object that can query the given entity type.
* @inheritdoc
*/
public function getAggregate($entity_type, $conjunction, EntityManager $entity_manager) {
throw new QueryException('Aggregation over configuration entities is not supported');

View File

@ -0,0 +1,51 @@
<?php
/**
* @file
* Contains \Drupal\Core\Entity\Query\QueryFactoryInterface.
*/
namespace Drupal\Core\Entity\Query;
use Drupal\Core\Entity\EntityManager;
/**
* Defines an interface for QueryFactory classes.
*/
interface QueryFactoryInterface {
/**
* Instantiates an entity query for a given entity type.
*
* @param string $entity_type
* The entity type for the query.
* @param string $conjunction
* The operator to use to combine conditions: 'AND' or 'OR'.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager that handles the entity type.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager that handles the entity type.
*
* @return \Drupal\Core\Entity\Query\QueryInterface
* An entity query for a specific configuration entity type.
*/
public function get($entity_type, $conjunction, EntityManager $entity_manager);
/**
* Returns a aggregation query object for a given entity type.
*
* @param string $entity_type
* The entity type.
* @param string $conjunction
* - AND: all of the conditions on the query need to match.
* - OR: at least one of the conditions on the query need to match.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager that handles the entity type.
*
* @throws \Drupal\Core\Entity\Query\QueryException
* @return \Drupal\Core\Entity\Query\QueryAggregateInterface
* The query object that can query the given entity type.
*/
public function getAggregate($entity_type, $conjunction, EntityManager $entity_manager);
}

View File

@ -9,6 +9,7 @@ namespace Drupal\field_sql_storage\Entity;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\Query\QueryFactoryInterface;
/**
* Factory class creating entity query objects for the SQL backend.
@ -16,7 +17,14 @@ use Drupal\Core\Entity\EntityManager;
* @see \Drupal\field_sql_storage\Entity\Query
* @see \Drupal\field_sql_storage\Entity\QueryAggregate
*/
class QueryFactory {
class QueryFactory implements QueryFactoryInterface {
/**
* The database connection to use.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a QueryFactory object.