mirror of
https://github.com/doctrine/orm.git
synced 2026-04-24 06:58:19 +02:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 242cf1a33d | |||
| da225a0db8 | |||
| 3ef5a30102 |
@@ -35,16 +35,6 @@ jobs:
|
||||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
|
||||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
|
||||
|
||||
- name: "Create and/or Switch to new Release Branch"
|
||||
uses: "laminas/automatic-releases@v1"
|
||||
with:
|
||||
command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor"
|
||||
env:
|
||||
"GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }}
|
||||
"SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }}
|
||||
"GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }}
|
||||
"GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}
|
||||
|
||||
- name: "Create new milestones"
|
||||
uses: "laminas/automatic-releases@v1"
|
||||
with:
|
||||
|
||||
@@ -20,9 +20,11 @@
|
||||
namespace Doctrine\ORM;
|
||||
|
||||
use Countable;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\DBAL\Cache\QueryCacheProfile;
|
||||
use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
|
||||
use Doctrine\Persistence\Mapping\MappingException;
|
||||
use Doctrine\ORM\Query\Parameter;
|
||||
use Doctrine\ORM\Cache\QueryCacheKey;
|
||||
use Traversable;
|
||||
@@ -420,15 +422,12 @@ abstract class AbstractQuery
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ($value instanceof Traversable) {
|
||||
if ($value instanceof Collection) {
|
||||
$value = iterator_to_array($value);
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $key => $paramValue) {
|
||||
$paramValue = $this->processParameterValue($paramValue);
|
||||
$value[$key] = is_array($paramValue) ? reset($paramValue) : $paramValue;
|
||||
}
|
||||
$value = $this->processArrayParameterValue($value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
@@ -451,6 +450,47 @@ abstract class AbstractQuery
|
||||
// Silence any mapping exceptions. These can occur if the object in
|
||||
// question is not a mapped entity, in which case we just don't do
|
||||
// any preparation on the value.
|
||||
|
||||
$value = $this->potentiallyProcessIterable($value);
|
||||
} catch (MappingException $e) {
|
||||
// as previous, but depending on MappingDriver this exception from Persistence
|
||||
// is thrown and not the ORM one.
|
||||
|
||||
$value = $this->potentiallyProcessIterable($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* If no mapping is detected, trying to resolve the value as a Traversable
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function potentiallyProcessIterable($value)
|
||||
{
|
||||
if ($value instanceof Traversable) {
|
||||
$value = iterator_to_array($value);
|
||||
$value = $this->processArrayParameterValue($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a parameter value which was previously identified as an array
|
||||
*
|
||||
* @param mixed[] $value
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function processArrayParameterValue(array $value): array
|
||||
{
|
||||
foreach ($value as $key => $paramValue) {
|
||||
$paramValue = $this->processParameterValue($paramValue);
|
||||
$value[$key] = is_array($paramValue) ? reset($paramValue) : $paramValue;
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace Doctrine\Tests\Models\CMS;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* Description of CmsGroup
|
||||
*
|
||||
@@ -9,7 +13,7 @@ namespace Doctrine\Tests\Models\CMS;
|
||||
* @Entity
|
||||
* @Table(name="cms_groups")
|
||||
*/
|
||||
class CmsGroup
|
||||
class CmsGroup implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @Id
|
||||
@@ -26,6 +30,11 @@ class CmsGroup
|
||||
*/
|
||||
public $users;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->users = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
@@ -41,5 +50,13 @@ class CmsGroup
|
||||
public function getUsers() {
|
||||
return $this->users;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayCollection|Traversable
|
||||
*/
|
||||
public function getIterator()
|
||||
{
|
||||
return $this->getUsers();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use Doctrine\Tests\Mocks\DriverConnectionMock;
|
||||
use Doctrine\Tests\Mocks\EntityManagerMock;
|
||||
use Doctrine\Tests\Mocks\StatementArrayMock;
|
||||
use Doctrine\Tests\Models\CMS\CmsAddress;
|
||||
use Doctrine\Tests\Models\CMS\CmsGroup;
|
||||
use Doctrine\Tests\Models\CMS\CmsUser;
|
||||
use Doctrine\Tests\Models\Generic\DateTimeModel;
|
||||
use Doctrine\Tests\OrmTestCase;
|
||||
@@ -240,6 +241,15 @@ class QueryTest extends OrmTestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testProcessParameterValueWithIterableEntityShouldNotBeTreatedAsIterable(): void
|
||||
{
|
||||
$group = new CmsGroup();
|
||||
$group->id = 1;
|
||||
|
||||
$query = $this->_em->createQuery('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.group IN (:group)');
|
||||
self::assertEquals(1, $query->processParameterValue($group));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-2224
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user