1
0
mirror of synced 2025-01-29 19:41:45 +03:00

Added missing BC compatibility in QueryBuilder.

This commit is contained in:
Guilherme Blanco 2012-05-29 14:52:30 -04:00
parent e4935e58f2
commit 6521e51170
2 changed files with 42 additions and 10 deletions

View File

@ -150,7 +150,7 @@ abstract class AbstractQuery
/**
* Get all defined parameters.
*
* @return array The defined query parameters.
* @return \Doctrine\Common\Collections\ArrayCollection The defined query parameters.
*/
public function getParameters()
{

View File

@ -355,7 +355,24 @@ class QueryBuilder
*/
public function setParameter($key, $value, $type = null)
{
$this->parameters->add(new Query\Parameter($key, $value, $type));
$filteredParameters = $this->parameters->filter(
function ($parameter) use ($key)
{
// Must not be identical because of string to integer conversion
return ($key == $parameter->getName());
}
);
if (count($filteredParameters)) {
$parameter = $filteredParameters->first();
$parameter->setValue($value, $type);
return $this;
}
$parameter = new Query\Parameter($key, $value, $type);
$this->parameters->add($parameter);
return $this;
}
@ -374,11 +391,24 @@ class QueryBuilder
)));
* </code>
*
* @param \Doctrine\Common\Collections\ArrayCollections $params The query parameters to set.
* @param \Doctrine\Common\Collections\ArrayCollection|array $params The query parameters to set.
* @return QueryBuilder This QueryBuilder instance.
*/
public function setParameters(ArrayCollection $parameters)
public function setParameters($parameters)
{
// BC compatibility with 2.3-
if (is_array($parameters)) {
$parameterCollection = new ArrayCollection();
foreach ($parameters as $key => $value) {
$parameter = new Query\Parameter($key, $value);
$parameterCollection->add($parameter);
}
$parameters = $parameterCollection;
}
$this->parameters = $parameters;
return $this;
@ -387,7 +417,7 @@ class QueryBuilder
/**
* Gets all defined query parameters for the query being constructed.
*
* @return array The currently defined query parameters.
* @return \Doctrine\Common\Collections\ArrayCollection The currently defined query parameters.
*/
public function getParameters()
{
@ -403,13 +433,15 @@ class QueryBuilder
*/
public function getParameter($key)
{
foreach ($this->parameters->getIterator() as $parameter) {
if ($parameter->getName() === $key) {
return $parameter;
$filteredParameters = $this->parameters->filter(
function ($parameter) use ($key)
{
// Must not be identical because of string to integer conversion
return ($key == $parameter->getName());
}
}
);
return null;
return count($filteredParameters) ? $filteredParameters->first() : null;
}
/**