Skip to content

Commit

Permalink
Breaking change: Backend requires a Query instance as argument
Browse files Browse the repository at this point in the history
- Change `getObjectCountByQuery()` to require an instance of `QueryInterface`
- Change `getObjectDataByQuery()` to require an instance of `QueryInterface`
  • Loading branch information
cundd committed Dec 18, 2018
1 parent ea75028 commit dac8157
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Classes/VirtualObject/Persistence/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public function removeRow($tableName, array $identifier)
return $this->concreteBackend->removeRow($tableName, $identifier);
}

public function getObjectCountByQuery($tableName, $query)
public function getObjectCountByQuery($tableName, QueryInterface $query)
{
return $this->concreteBackend->getObjectCountByQuery($tableName, $query);
}

public function getObjectDataByQuery($tableName, $query)
public function getObjectDataByQuery($tableName, QueryInterface $query)
{
return $this->concreteBackend->getObjectDataByQuery($tableName, $query);
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/VirtualObject/Persistence/Backend/DoctrineBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function removeRow($tableName, array $identifier)
}
}

public function getObjectCountByQuery($tableName, $query)
public function getObjectCountByQuery($tableName, QueryInterface $query)
{
$this->assertValidTableName($tableName);

Expand Down Expand Up @@ -99,7 +99,7 @@ public function getObjectCountByQuery($tableName, $query)
return $result['count'];
}

public function getObjectDataByQuery($tableName, $query)
public function getObjectDataByQuery($tableName, QueryInterface $query)
{
$this->assertValidTableName($tableName);

Expand Down
10 changes: 5 additions & 5 deletions Classes/VirtualObject/Persistence/Backend/V7Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function removeRow($tableName, array $identifier)
return $result;
}

public function getObjectCountByQuery($tableName, $query)
public function getObjectCountByQuery($tableName, QueryInterface $query)
{
$this->assertValidTableName($tableName);
try {
Expand All @@ -96,7 +96,7 @@ public function getObjectCountByQuery($tableName, $query)
return intval($row['count']);
}

public function getObjectDataByQuery($tableName, $query)
public function getObjectDataByQuery($tableName, QueryInterface $query)
{
$this->assertValidTableName($tableName);
try {
Expand Down Expand Up @@ -211,9 +211,9 @@ protected function createWhereStatementFromQuery($query, $tableName)
/**
* Replace query placeholders in a query part by the given parameters
*
* @param string &$sqlString The query part with placeholders
* @param array $parameters The parameters
* @param string $tableName
* @param string &$sqlString The query part with placeholders
* @param array $parameters The parameters
* @param string $tableName
*
* @throws Exception
* @return string
Expand Down
32 changes: 15 additions & 17 deletions Classes/VirtualObject/Persistence/Backend/WhereClauseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,39 @@ public function __construct()
*
* The current WHERE-clause will be reset
*
* @param QueryInterface|array $query
* @param callable|null $prepareValue `mixed function(mixed $queryValue)`
* @param callable|null $escapeColumnName `string function(string $propertyName)`
* @param string $bindingPrefix
* @param QueryInterface $query
* @param callable|null $prepareValue `mixed function(mixed $queryValue)`
* @param callable|null $escapeColumnName `string function(string $propertyName)`
* @param string $bindingPrefix
* @return self
* @throws MissingConfigurationException
* @throws InvalidColumnNameException
*/
public function build($query, callable $prepareValue = null, callable $escapeColumnName = null, $bindingPrefix = '')
{
public function build(
QueryInterface $query,
callable $prepareValue = null,
callable $escapeColumnName = null,
$bindingPrefix = ''
) {
$this->reset();
$configuration = null;

if ($query instanceof Query && $query->getStatement()) {
throw new \LogicException('`Query->getStatement()` is not supported by the Doctrine Backend');
}
if ($query instanceof QueryInterface) {
$configuration = $query->getConfiguration();
$query = $query->getConstraint();
}

return $this->addConstraints(
$query,
$query->getConstraint(),
$prepareValue,
$escapeColumnName,
$bindingPrefix,
QueryInterface::COMBINATOR_AND,
$configuration
$query->getConfiguration()
);
}

/**
* Add multiple constraints to the WHERE-clause
*
* @param array $query Map of property => value pairs to add constraints
* @param array $constraints Map of property => value pairs to add constraints
* @param callable|null $prepareValue
* @param callable|null $escapeColumnName
* @param string $bindingPrefix
Expand All @@ -78,15 +76,15 @@ public function build($query, callable $prepareValue = null, callable $escapeCol
* @throws InvalidOperatorException
*/
public function addConstraints(
array $query,
array $constraints,
callable $prepareValue = null,
callable $escapeColumnName = null,
$bindingPrefix = '',
$combinator = QueryInterface::COMBINATOR_AND,
ConfigurationInterface $configuration = null
) {
WhereClause::assertCombinator($combinator);
foreach ($query as $property => $value) {
foreach ($constraints as $property => $value) {
$this->addConstraint(
$property,
$value,
Expand Down
12 changes: 6 additions & 6 deletions Classes/VirtualObject/Persistence/BackendInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ public function removeRow($tableName, array $identifier);
/**
* Returns the number of items matching the query
*
* @param string $tableName Database table name
* @param array|QueryInterface $query A Query instance or a map of key value pairs to construct the WHERE clause
* @param string $tableName Database table name
* @param QueryInterface $query A Query instance to construct the WHERE clause
* @return integer
* @throws InvalidTableNameException if the table name is not valid
* @throws InvalidOperatorException if the where clause could not be built
* @throws SqlErrorException on SQL errors
*/
public function getObjectCountByQuery($tableName, $query);
public function getObjectCountByQuery($tableName, QueryInterface $query);

/**
* Returns the object data matching the $query
*
* @param string $tableName Database table name
* @param array|QueryInterface $query A Query instance or a map of key value pairs to construct the WHERE clause
* @param string $tableName Database table name
* @param QueryInterface $query A Query instance to construct the WHERE clause
* @return array
* @throws InvalidTableNameException if the table name is not valid
* @throws InvalidOperatorException if the where clause could not be built
* @throws SqlErrorException on SQL errors
*/
public function getObjectDataByQuery($tableName, $query);
public function getObjectDataByQuery($tableName, QueryInterface $query);
}

0 comments on commit dac8157

Please sign in to comment.