Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6958d77

Browse files
committed
do not depend on the QueryBuilder from the ORM
1 parent 4d11bca commit 6958d77

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Doctrine\Common\Collections\Collection;
1515
use Doctrine\Common\Persistence\ManagerRegistry;
1616
use Doctrine\Common\Persistence\ObjectManager;
17-
use Doctrine\ORM\QueryBuilder;
1817
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
1918
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
2019
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
@@ -85,13 +84,16 @@ public static function createChoiceName($choice, $key, $value): string
8584
* For instance in ORM two query builders with an equal SQL string and
8685
* equal parameters are considered to be equal.
8786
*
87+
* @param object $queryBuilder A query builder, type declaration is not present here as there
88+
* is no common base class for the different implementations
89+
*
8890
* @return array|null Array with important QueryBuilder parts or null if
8991
* they can't be determined
9092
*
9193
* @internal This method is public to be usable as callback. It should not
9294
* be used in user code.
9395
*/
94-
public function getQueryBuilderPartsForCachingHash(QueryBuilder $queryBuilder): ?array
96+
public function getQueryBuilderPartsForCachingHash($queryBuilder): ?array
9597
{
9698
return null;
9799
}

src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public function configureOptions(OptionsResolver $resolver)
5353
*/
5454
public function getLoader(ObjectManager $manager, $queryBuilder, $class)
5555
{
56+
if (!$queryBuilder instanceof QueryBuilder) {
57+
throw new \TypeError(sprintf('Expected an instance of %s, but got %s.', QueryBuilder::class, \is_object($queryBuilder) ? \get_class($queryBuilder) : \gettype($queryBuilder)));
58+
}
59+
5660
return new ORMQueryBuilderLoader($queryBuilder);
5761
}
5862

@@ -68,11 +72,17 @@ public function getBlockPrefix()
6872
* We consider two query builders with an equal SQL string and
6973
* equal parameters to be equal.
7074
*
75+
* @param QueryBuilder $queryBuilder
76+
*
7177
* @internal This method is public to be usable as callback. It should not
7278
* be used in user code.
7379
*/
74-
public function getQueryBuilderPartsForCachingHash(QueryBuilder $queryBuilder): ?array
80+
public function getQueryBuilderPartsForCachingHash($queryBuilder): ?array
7581
{
82+
if (!$queryBuilder instanceof QueryBuilder) {
83+
throw new \TypeError(sprintf('Expected an instance of %s, but got %s.', QueryBuilder::class, \is_object($queryBuilder) ? \get_class($queryBuilder) : \gettype($queryBuilder)));
84+
}
85+
7686
return [
7787
$queryBuilder->getQuery()->getSQL(),
7888
array_map([$this, 'parameterToArray'], $queryBuilder->getParameters()->toArray()),

0 commit comments

Comments
 (0)