Skip to content
Browse files

Made setParameters()/excute()/iterate() BC compatible.

  • Loading branch information...
1 parent d8e165d commit b3e7493278ce4915d7b741a4ea3cd390030b82bb @guilhermeblanco guilhermeblanco committed
View
20 lib/Doctrine/ORM/AbstractQuery.php
@@ -180,12 +180,16 @@ function ($parameter) use ($key)
/**
* Sets a collection of query parameters.
*
- * @param \Doctrine\Common\Collections\ArrayCollection $parameters
+ * @param \Doctrine\Common\Collections\ArrayCollection|array $parameters
*
* @return \Doctrine\ORM\AbstractQuery This query instance.
*/
- public function setParameters(ArrayCollection $parameters)
+ public function setParameters($parameters)
{
+ if (is_array($parameters)) {
+ $parameters = new ArrayCollection($parameters);
+ }
+
$this->parameters = $parameters;
return $this;
@@ -659,17 +663,17 @@ public function getHints()
* Executes the query and returns an IterableResult that can be used to incrementally
* iterate over the result.
*
- * @param \Doctrine\Common\Collections\ArrayCollection $parameters The query parameters.
+ * @param \Doctrine\Common\Collections\ArrayCollection|array $parameters The query parameters.
* @param integer $hydrationMode The hydration mode to use.
* @return \Doctrine\ORM\Internal\Hydration\IterableResult
*/
- public function iterate(ArrayCollection $parameters = null, $hydrationMode = null)
+ public function iterate($parameters = null, $hydrationMode = null)
{
if ($hydrationMode !== null) {
$this->setHydrationMode($hydrationMode);
}
- if ($parameters) {
+ if ( ! empty($parameters)) {
$this->setParameters($parameters);
}
@@ -683,17 +687,17 @@ public function iterate(ArrayCollection $parameters = null, $hydrationMode = nul
/**
* Executes the query.
*
- * @param \Doctrine\Common\Collections\ArrayCollection $parameters Query parameters.
+ * @param \Doctrine\Common\Collections\ArrayCollection|array $parameters Query parameters.
* @param integer $hydrationMode Processing mode to be used during the hydration process.
* @return mixed
*/
- public function execute(ArrayCollection $parameters = null, $hydrationMode = null)
+ public function execute($parameters = null, $hydrationMode = null)
{
if ($hydrationMode !== null) {
$this->setHydrationMode($hydrationMode);
}
- if ($parameters) {
+ if ( ! empty($parameters)) {
$this->setParameters($parameters);
}
View
4 lib/Doctrine/ORM/Query.php
@@ -526,11 +526,11 @@ public function getMaxResults()
* Executes the query and returns an IterableResult that can be used to incrementally
* iterated over the result.
*
- * @param \Doctrine\Common\Collections\ArrayCollection $parameters The query parameters.
+ * @param \Doctrine\Common\Collections\ArrayCollection|array $parameters The query parameters.
* @param integer $hydrationMode The hydration mode to use.
* @return \Doctrine\ORM\Internal\Hydration\IterableResult
*/
- public function iterate(ArrayCollection $parameters = null, $hydrationMode = self::HYDRATE_OBJECT)
+ public function iterate($parameters = null, $hydrationMode = self::HYDRATE_OBJECT)
{
$this->setHint(self::HINT_INTERNAL_ITERATION, true);
View
10 tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php
@@ -14,6 +14,7 @@ class HydrationCacheTest extends OrmFunctionalTestCase
public function setUp()
{
$this->useModelSet('cms');
+
parent::setUp();
$user = new CmsUser;
@@ -72,14 +73,17 @@ public function testHydrationParametersSerialization()
$user = new CmsUser();
$user->id = 1;
- $dql = "SELECT u FROM Doctrine\Tests\Models\Cms\CmsUser u WHERE u.id = ?1";
+ $dql = "SELECT u FROM Doctrine\Tests\Models\Cms\CmsUser u WHERE u.id = ?1";
$query = $this->_em->createQuery($dql)
- ->setParameter(1, $user)
- ->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache));
+ ->setParameter(1, $user)
+ ->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache));
$query->getResult();
+
$c = $this->getCurrentQueryCount();
+
$query->getResult();
+
$this->assertEquals($c, $this->getCurrentQueryCount(), "Should not execute query. Its cached!");
}
}

0 comments on commit b3e7493

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