Skip to content

Commit

Permalink
bug #34600 [DoctrineBridge] do not depend on the QueryBuilder from th…
Browse files Browse the repository at this point in the history
…e ORM (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[DoctrineBridge] do not depend on the QueryBuilder from the ORM

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34581
| License       | MIT
| Doc PR        |

Commits
-------

6958d77 do not depend on the QueryBuilder from the ORM
  • Loading branch information
fabpot committed Nov 30, 2019
2 parents 4d11bca + 6958d77 commit 0a2a176
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
Expand Down Expand Up @@ -85,13 +84,16 @@ public static function createChoiceName($choice, $key, $value): string
* For instance in ORM two query builders with an equal SQL string and
* equal parameters are considered to be equal.
*
* @param object $queryBuilder A query builder, type declaration is not present here as there
* is no common base class for the different implementations
*
* @return array|null Array with important QueryBuilder parts or null if
* they can't be determined
*
* @internal This method is public to be usable as callback. It should not
* be used in user code.
*/
public function getQueryBuilderPartsForCachingHash(QueryBuilder $queryBuilder): ?array
public function getQueryBuilderPartsForCachingHash($queryBuilder): ?array
{
return null;
}
Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public function configureOptions(OptionsResolver $resolver)
*/
public function getLoader(ObjectManager $manager, $queryBuilder, $class)
{
if (!$queryBuilder instanceof QueryBuilder) {
throw new \TypeError(sprintf('Expected an instance of %s, but got %s.', QueryBuilder::class, \is_object($queryBuilder) ? \get_class($queryBuilder) : \gettype($queryBuilder)));
}

return new ORMQueryBuilderLoader($queryBuilder);
}

Expand All @@ -68,11 +72,17 @@ public function getBlockPrefix()
* We consider two query builders with an equal SQL string and
* equal parameters to be equal.
*
* @param QueryBuilder $queryBuilder
*
* @internal This method is public to be usable as callback. It should not
* be used in user code.
*/
public function getQueryBuilderPartsForCachingHash(QueryBuilder $queryBuilder): ?array
public function getQueryBuilderPartsForCachingHash($queryBuilder): ?array
{
if (!$queryBuilder instanceof QueryBuilder) {
throw new \TypeError(sprintf('Expected an instance of %s, but got %s.', QueryBuilder::class, \is_object($queryBuilder) ? \get_class($queryBuilder) : \gettype($queryBuilder)));
}

return [
$queryBuilder->getQuery()->getSQL(),
array_map([$this, 'parameterToArray'], $queryBuilder->getParameters()->toArray()),
Expand Down

0 comments on commit 0a2a176

Please sign in to comment.