Skip to content
Browse files

Added missing BC compatibility in QueryBuilder.

  • Loading branch information...
1 parent e4935e5 commit 6521e511706baa897f4500b05cb835d749d65692 @guilhermeblanco guilhermeblanco committed May 29, 2012
Showing with 42 additions and 10 deletions.
  1. +1 −1 lib/Doctrine/ORM/AbstractQuery.php
  2. +41 −9 lib/Doctrine/ORM/QueryBuilder.php
View
2 lib/Doctrine/ORM/AbstractQuery.php
@@ -150,7 +150,7 @@ public function free()
/**
* Get all defined parameters.
*
- * @return array The defined query parameters.
+ * @return \Doctrine\Common\Collections\ArrayCollection The defined query parameters.
*/
public function getParameters()
{
View
50 lib/Doctrine/ORM/QueryBuilder.php
@@ -355,7 +355,24 @@ public function getRootEntities()
*/
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 @@ public function setParameter($key, $value, $type = null)
)));
* </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 @@ public function setParameters(ArrayCollection $parameters)
/**
* 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 @@ public function getParameters()
*/
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;
}
/**

0 comments on commit 6521e51

Please sign in to comment.
Something went wrong with that request. Please try again.