vendor/doctrine/orm/src/Query.php line 327

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\ORM;
  4. use Doctrine\Common\Cache\Cache;
  5. use Doctrine\Common\Cache\Psr6\CacheAdapter;
  6. use Doctrine\Common\Cache\Psr6\DoctrineProvider;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\DBAL\Cache\QueryCacheProfile;
  9. use Doctrine\DBAL\LockMode;
  10. use Doctrine\DBAL\Types\Type;
  11. use Doctrine\Deprecations\Deprecation;
  12. use Doctrine\ORM\Internal\Hydration\IterableResult;
  13. use Doctrine\ORM\Mapping\ClassMetadata;
  14. use Doctrine\ORM\Query\AST\DeleteStatement;
  15. use Doctrine\ORM\Query\AST\SelectStatement;
  16. use Doctrine\ORM\Query\AST\UpdateStatement;
  17. use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
  18. use Doctrine\ORM\Query\Parameter;
  19. use Doctrine\ORM\Query\ParameterTypeInferer;
  20. use Doctrine\ORM\Query\Parser;
  21. use Doctrine\ORM\Query\ParserResult;
  22. use Doctrine\ORM\Query\QueryException;
  23. use Doctrine\ORM\Query\ResultSetMapping;
  24. use Doctrine\ORM\Utility\HierarchyDiscriminatorResolver;
  25. use Psr\Cache\CacheItemPoolInterface;
  26. use function array_keys;
  27. use function array_values;
  28. use function assert;
  29. use function count;
  30. use function get_debug_type;
  31. use function in_array;
  32. use function is_int;
  33. use function ksort;
  34. use function md5;
  35. use function method_exists;
  36. use function reset;
  37. use function serialize;
  38. use function sha1;
  39. use function stripos;
  40. /**
  41. * A Query object represents a DQL query.
  42. *
  43. * @final
  44. */
  45. class Query extends AbstractQuery
  46. {
  47. /**
  48. * A query object is in CLEAN state when it has NO unparsed/unprocessed DQL parts.
  49. */
  50. public const STATE_CLEAN = 1;
  51. /**
  52. * A query object is in state DIRTY when it has DQL parts that have not yet been
  53. * parsed/processed. This is automatically defined as DIRTY when addDqlQueryPart
  54. * is called.
  55. */
  56. public const STATE_DIRTY = 2;
  57. /* Query HINTS */
  58. /**
  59. * The refresh hint turns any query into a refresh query with the result that
  60. * any local changes in entities are overridden with the fetched values.
  61. */
  62. public const HINT_REFRESH = 'doctrine.refresh';
  63. public const HINT_CACHE_ENABLED = 'doctrine.cache.enabled';
  64. public const HINT_CACHE_EVICT = 'doctrine.cache.evict';
  65. /**
  66. * Internal hint: is set to the proxy entity that is currently triggered for loading
  67. */
  68. public const HINT_REFRESH_ENTITY = 'doctrine.refresh.entity';
  69. /**
  70. * The forcePartialLoad query hint forces a particular query to return
  71. * partial objects.
  72. *
  73. * @todo Rename: HINT_OPTIMIZE
  74. */
  75. public const HINT_FORCE_PARTIAL_LOAD = 'doctrine.forcePartialLoad';
  76. /**
  77. * The includeMetaColumns query hint causes meta columns like foreign keys and
  78. * discriminator columns to be selected and returned as part of the query result.
  79. *
  80. * This hint does only apply to non-object queries.
  81. */
  82. public const HINT_INCLUDE_META_COLUMNS = 'doctrine.includeMetaColumns';
  83. /**
  84. * An array of class names that implement \Doctrine\ORM\Query\TreeWalker and
  85. * are iterated and executed after the DQL has been parsed into an AST.
  86. */
  87. public const HINT_CUSTOM_TREE_WALKERS = 'doctrine.customTreeWalkers';
  88. /**
  89. * A string with a class name that implements \Doctrine\ORM\Query\TreeWalker
  90. * and is used for generating the target SQL from any DQL AST tree.
  91. */
  92. public const HINT_CUSTOM_OUTPUT_WALKER = 'doctrine.customOutputWalker';
  93. /**
  94. * Marks queries as creating only read only objects.
  95. *
  96. * If the object retrieved from the query is already in the identity map
  97. * then it does not get marked as read only if it wasn't already.
  98. */
  99. public const HINT_READ_ONLY = 'doctrine.readOnly';
  100. public const HINT_INTERNAL_ITERATION = 'doctrine.internal.iteration';
  101. public const HINT_LOCK_MODE = 'doctrine.lockMode';
  102. /**
  103. * The current state of this query.
  104. *
  105. * @var int
  106. * @psalm-var self::STATE_*
  107. */
  108. private $state = self::STATE_DIRTY;
  109. /**
  110. * A snapshot of the parameter types the query was parsed with.
  111. *
  112. * @var array<string,Type>
  113. */
  114. private $parsedTypes = [];
  115. /**
  116. * Cached DQL query.
  117. *
  118. * @var string|null
  119. */
  120. private $dql = null;
  121. /**
  122. * The parser result that holds DQL => SQL information.
  123. *
  124. * @var ParserResult
  125. */
  126. private $parserResult;
  127. /**
  128. * The first result to return (the "offset").
  129. *
  130. * @var int
  131. */
  132. private $firstResult = 0;
  133. /**
  134. * The maximum number of results to return (the "limit").
  135. *
  136. * @var int|null
  137. */
  138. private $maxResults = null;
  139. /**
  140. * The cache driver used for caching queries.
  141. *
  142. * @var CacheItemPoolInterface|null
  143. */
  144. private $queryCache;
  145. /**
  146. * Whether or not expire the query cache.
  147. *
  148. * @var bool
  149. */
  150. private $expireQueryCache = false;
  151. /**
  152. * The query cache lifetime.
  153. *
  154. * @var int|null
  155. */
  156. private $queryCacheTTL;
  157. /**
  158. * Whether to use a query cache, if available. Defaults to TRUE.
  159. *
  160. * @var bool
  161. */
  162. private $useQueryCache = true;
  163. /**
  164. * Gets the SQL query/queries that correspond to this DQL query.
  165. *
  166. * @return list<string>|string The built sql query or an array of all sql queries.
  167. */
  168. public function getSQL()
  169. {
  170. return $this->parse()->getSqlExecutor()->getSqlStatements();
  171. }
  172. /**
  173. * Returns the corresponding AST for this DQL query.
  174. *
  175. * @return SelectStatement|UpdateStatement|DeleteStatement
  176. */
  177. public function getAST()
  178. {
  179. $parser = new Parser($this);
  180. return $parser->getAST();
  181. }
  182. /**
  183. * {@inheritDoc}
  184. *
  185. * @return ResultSetMapping
  186. */
  187. protected function getResultSetMapping()
  188. {
  189. // parse query or load from cache
  190. if ($this->_resultSetMapping === null) {
  191. $this->_resultSetMapping = $this->parse()->getResultSetMapping();
  192. }
  193. return $this->_resultSetMapping;
  194. }
  195. /**
  196. * Parses the DQL query, if necessary, and stores the parser result.
  197. *
  198. * Note: Populates $this->_parserResult as a side-effect.
  199. */
  200. private function parse(): ParserResult
  201. {
  202. $types = [];
  203. foreach ($this->parameters as $parameter) {
  204. /** @var Query\Parameter $parameter */
  205. $types[$parameter->getName()] = $parameter->getType();
  206. }
  207. // Return previous parser result if the query and the filter collection are both clean
  208. if ($this->state === self::STATE_CLEAN && $this->parsedTypes === $types && $this->_em->isFiltersStateClean()) {
  209. return $this->parserResult;
  210. }
  211. $this->state = self::STATE_CLEAN;
  212. $this->parsedTypes = $types;
  213. $queryCache = $this->queryCache ?? $this->_em->getConfiguration()->getQueryCache();
  214. // Check query cache.
  215. if (! ($this->useQueryCache && $queryCache)) {
  216. $parser = new Parser($this);
  217. $this->parserResult = $parser->parse();
  218. return $this->parserResult;
  219. }
  220. $cacheItem = $queryCache->getItem($this->getQueryCacheId());
  221. if (! $this->expireQueryCache && $cacheItem->isHit()) {
  222. $cached = $cacheItem->get();
  223. if ($cached instanceof ParserResult) {
  224. // Cache hit.
  225. $this->parserResult = $cached;
  226. return $this->parserResult;
  227. }
  228. }
  229. // Cache miss.
  230. $parser = new Parser($this);
  231. $this->parserResult = $parser->parse();
  232. $queryCache->save($cacheItem->set($this->parserResult)->expiresAfter($this->queryCacheTTL));
  233. return $this->parserResult;
  234. }
  235. /**
  236. * {@inheritDoc}
  237. */
  238. protected function _doExecute()
  239. {
  240. $executor = $this->parse()->getSqlExecutor();
  241. if ($this->_queryCacheProfile) {
  242. $executor->setQueryCacheProfile($this->_queryCacheProfile);
  243. } else {
  244. $executor->removeQueryCacheProfile();
  245. }
  246. if ($this->_resultSetMapping === null) {
  247. $this->_resultSetMapping = $this->parserResult->getResultSetMapping();
  248. }
  249. // Prepare parameters
  250. $paramMappings = $this->parserResult->getParameterMappings();
  251. $paramCount = count($this->parameters);
  252. $mappingCount = count($paramMappings);
  253. if ($paramCount > $mappingCount) {
  254. throw QueryException::tooManyParameters($mappingCount, $paramCount);
  255. }
  256. if ($paramCount < $mappingCount) {
  257. throw QueryException::tooFewParameters($mappingCount, $paramCount);
  258. }
  259. // evict all cache for the entity region
  260. if ($this->hasCache && isset($this->_hints[self::HINT_CACHE_EVICT]) && $this->_hints[self::HINT_CACHE_EVICT]) {
  261. $this->evictEntityCacheRegion();
  262. }
  263. [$sqlParams, $types] = $this->processParameterMappings($paramMappings);
  264. $this->evictResultSetCache(
  265. $executor,
  266. $sqlParams,
  267. $types,
  268. $this->_em->getConnection()->getParams()
  269. );
  270. return $executor->execute($this->_em->getConnection(), $sqlParams, $types);
  271. }
  272. /**
  273. * @param array<string,mixed> $sqlParams
  274. * @param array<string,Type> $types
  275. * @param array<string,mixed> $connectionParams
  276. */
  277. private function evictResultSetCache(
  278. AbstractSqlExecutor $executor,
  279. array $sqlParams,
  280. array $types,
  281. array $connectionParams
  282. ): void {
  283. if ($this->_queryCacheProfile === null || ! $this->getExpireResultCache()) {
  284. return;
  285. }
  286. $cache = method_exists(QueryCacheProfile::class, 'getResultCache')
  287. ? $this->_queryCacheProfile->getResultCache()
  288. : $this->_queryCacheProfile->getResultCacheDriver();
  289. assert($cache !== null);
  290. $statements = (array) $executor->getSqlStatements(); // Type casted since it can either be a string or an array
  291. foreach ($statements as $statement) {
  292. $cacheKeys = $this->_queryCacheProfile->generateCacheKeys($statement, $sqlParams, $types, $connectionParams);
  293. $cache instanceof CacheItemPoolInterface
  294. ? $cache->deleteItem(reset($cacheKeys))
  295. : $cache->delete(reset($cacheKeys));
  296. }
  297. }
  298. /**
  299. * Evict entity cache region
  300. */
  301. private function evictEntityCacheRegion(): void
  302. {
  303. $AST = $this->getAST();
  304. if ($AST instanceof SelectStatement) {
  305. throw new QueryException('The hint "HINT_CACHE_EVICT" is not valid for select statements.');
  306. }
  307. $className = $AST instanceof DeleteStatement
  308. ? $AST->deleteClause->abstractSchemaName
  309. : $AST->updateClause->abstractSchemaName;
  310. $this->_em->getCache()->evictEntityRegion($className);
  311. }
  312. /**
  313. * Processes query parameter mappings.
  314. *
  315. * @param array<list<int>> $paramMappings
  316. *
  317. * @return mixed[][]
  318. * @psalm-return array{0: list<mixed>, 1: array}
  319. *
  320. * @throws Query\QueryException
  321. */
  322. private function processParameterMappings(array $paramMappings): array
  323. {
  324. $sqlParams = [];
  325. $types = [];
  326. foreach ($this->parameters as $parameter) {
  327. $key = $parameter->getName();
  328. if (! isset($paramMappings[$key])) {
  329. throw QueryException::unknownParameter($key);
  330. }
  331. [$value, $type] = $this->resolveParameterValue($parameter);
  332. foreach ($paramMappings[$key] as $position) {
  333. $types[$position] = $type;
  334. }
  335. $sqlPositions = $paramMappings[$key];
  336. // optimized multi value sql positions away for now,
  337. // they are not allowed in DQL anyways.
  338. $value = [$value];
  339. $countValue = count($value);
  340. for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
  341. $sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
  342. }
  343. }
  344. if (count($sqlParams) !== count($types)) {
  345. throw QueryException::parameterTypeMismatch();
  346. }
  347. if ($sqlParams) {
  348. ksort($sqlParams);
  349. $sqlParams = array_values($sqlParams);
  350. ksort($types);
  351. $types = array_values($types);
  352. }
  353. return [$sqlParams, $types];
  354. }
  355. /**
  356. * @return mixed[] tuple of (value, type)
  357. * @psalm-return array{0: mixed, 1: mixed}
  358. */
  359. private function resolveParameterValue(Parameter $parameter): array
  360. {
  361. if ($parameter->typeWasSpecified()) {
  362. return [$parameter->getValue(), $parameter->getType()];
  363. }
  364. $key = $parameter->getName();
  365. $originalValue = $parameter->getValue();
  366. $value = $originalValue;
  367. $rsm = $this->getResultSetMapping();
  368. if ($value instanceof ClassMetadata && isset($rsm->metadataParameterMapping[$key])) {
  369. $value = $value->getMetadataValue($rsm->metadataParameterMapping[$key]);
  370. }
  371. if ($value instanceof ClassMetadata && isset($rsm->discriminatorParameters[$key])) {
  372. $value = array_keys(HierarchyDiscriminatorResolver::resolveDiscriminatorsForClass($value, $this->_em));
  373. }
  374. $processedValue = $this->processParameterValue($value);
  375. return [
  376. $processedValue,
  377. $originalValue === $processedValue
  378. ? $parameter->getType()
  379. : ParameterTypeInferer::inferType($processedValue),
  380. ];
  381. }
  382. /**
  383. * Defines a cache driver to be used for caching queries.
  384. *
  385. * @deprecated Call {@see setQueryCache()} instead.
  386. *
  387. * @param Cache|null $queryCache Cache driver.
  388. *
  389. * @return $this
  390. */
  391. public function setQueryCacheDriver($queryCache): self
  392. {
  393. Deprecation::trigger(
  394. 'doctrine/orm',
  395. 'https://github.com/doctrine/orm/pull/9004',
  396. '%s is deprecated and will be removed in Doctrine 3.0. Use setQueryCache() instead.',
  397. __METHOD__
  398. );
  399. $this->queryCache = $queryCache ? CacheAdapter::wrap($queryCache) : null;
  400. return $this;
  401. }
  402. /**
  403. * Defines a cache driver to be used for caching queries.
  404. *
  405. * @return $this
  406. */
  407. public function setQueryCache(?CacheItemPoolInterface $queryCache): self
  408. {
  409. $this->queryCache = $queryCache;
  410. return $this;
  411. }
  412. /**
  413. * Defines whether the query should make use of a query cache, if available.
  414. *
  415. * @param bool $bool
  416. *
  417. * @return $this
  418. */
  419. public function useQueryCache($bool): self
  420. {
  421. $this->useQueryCache = $bool;
  422. return $this;
  423. }
  424. /**
  425. * Returns the cache driver used for query caching.
  426. *
  427. * @deprecated
  428. *
  429. * @return Cache|null The cache driver used for query caching or NULL, if
  430. * this Query does not use query caching.
  431. */
  432. public function getQueryCacheDriver(): ?Cache
  433. {
  434. Deprecation::trigger(
  435. 'doctrine/orm',
  436. 'https://github.com/doctrine/orm/pull/9004',
  437. '%s is deprecated and will be removed in Doctrine 3.0 without replacement.',
  438. __METHOD__
  439. );
  440. $queryCache = $this->queryCache ?? $this->_em->getConfiguration()->getQueryCache();
  441. return $queryCache ? DoctrineProvider::wrap($queryCache) : null;
  442. }
  443. /**
  444. * Defines how long the query cache will be active before expire.
  445. *
  446. * @param int|null $timeToLive How long the cache entry is valid.
  447. *
  448. * @return $this
  449. */
  450. public function setQueryCacheLifetime($timeToLive): self
  451. {
  452. if ($timeToLive !== null) {
  453. $timeToLive = (int) $timeToLive;
  454. }
  455. $this->queryCacheTTL = $timeToLive;
  456. return $this;
  457. }
  458. /**
  459. * Retrieves the lifetime of resultset cache.
  460. */
  461. public function getQueryCacheLifetime(): ?int
  462. {
  463. return $this->queryCacheTTL;
  464. }
  465. /**
  466. * Defines if the query cache is active or not.
  467. *
  468. * @param bool $expire Whether or not to force query cache expiration.
  469. *
  470. * @return $this
  471. */
  472. public function expireQueryCache($expire = true): self
  473. {
  474. $this->expireQueryCache = $expire;
  475. return $this;
  476. }
  477. /**
  478. * Retrieves if the query cache is active or not.
  479. */
  480. public function getExpireQueryCache(): bool
  481. {
  482. return $this->expireQueryCache;
  483. }
  484. public function free(): void
  485. {
  486. parent::free();
  487. $this->dql = null;
  488. $this->state = self::STATE_CLEAN;
  489. }
  490. /**
  491. * Sets a DQL query string.
  492. *
  493. * @param string|null $dqlQuery DQL Query.
  494. */
  495. public function setDQL($dqlQuery): self
  496. {
  497. if ($dqlQuery === null) {
  498. Deprecation::trigger(
  499. 'doctrine/orm',
  500. 'https://github.com/doctrine/orm/pull/9784',
  501. 'Calling %s with null is deprecated and will result in a TypeError in Doctrine 3.0',
  502. __METHOD__
  503. );
  504. return $this;
  505. }
  506. $this->dql = $dqlQuery;
  507. $this->state = self::STATE_DIRTY;
  508. return $this;
  509. }
  510. /**
  511. * Returns the DQL query that is represented by this query object.
  512. */
  513. public function getDQL(): ?string
  514. {
  515. return $this->dql;
  516. }
  517. /**
  518. * Returns the state of this query object
  519. * By default the type is Doctrine_ORM_Query_Abstract::STATE_CLEAN but if it appears any unprocessed DQL
  520. * part, it is switched to Doctrine_ORM_Query_Abstract::STATE_DIRTY.
  521. *
  522. * @see AbstractQuery::STATE_CLEAN
  523. * @see AbstractQuery::STATE_DIRTY
  524. *
  525. * @return int The query state.
  526. * @psalm-return self::STATE_* The query state.
  527. */
  528. public function getState(): int
  529. {
  530. return $this->state;
  531. }
  532. /**
  533. * Method to check if an arbitrary piece of DQL exists
  534. *
  535. * @param string $dql Arbitrary piece of DQL to check for.
  536. */
  537. public function contains($dql): bool
  538. {
  539. return stripos($this->getDQL(), $dql) !== false;
  540. }
  541. /**
  542. * Sets the position of the first result to retrieve (the "offset").
  543. *
  544. * @param int|null $firstResult The first result to return.
  545. *
  546. * @return $this
  547. */
  548. public function setFirstResult($firstResult): self
  549. {
  550. if (! is_int($firstResult)) {
  551. Deprecation::trigger(
  552. 'doctrine/orm',
  553. 'https://github.com/doctrine/orm/pull/9809',
  554. 'Calling %s with %s is deprecated and will result in a TypeError in Doctrine 3.0. Pass an integer.',
  555. __METHOD__,
  556. get_debug_type($firstResult)
  557. );
  558. $firstResult = (int) $firstResult;
  559. }
  560. $this->firstResult = $firstResult;
  561. $this->state = self::STATE_DIRTY;
  562. return $this;
  563. }
  564. /**
  565. * Gets the position of the first result the query object was set to retrieve (the "offset").
  566. * Returns 0 if {@link setFirstResult} was not applied to this query.
  567. *
  568. * @return int The position of the first result.
  569. */
  570. public function getFirstResult(): int
  571. {
  572. return $this->firstResult;
  573. }
  574. /**
  575. * Sets the maximum number of results to retrieve (the "limit").
  576. *
  577. * @param int|null $maxResults
  578. *
  579. * @return $this
  580. */
  581. public function setMaxResults($maxResults): self
  582. {
  583. if ($maxResults !== null) {
  584. $maxResults = (int) $maxResults;
  585. }
  586. $this->maxResults = $maxResults;
  587. $this->state = self::STATE_DIRTY;
  588. return $this;
  589. }
  590. /**
  591. * Gets the maximum number of results the query object was set to retrieve (the "limit").
  592. * Returns NULL if {@link setMaxResults} was not applied to this query.
  593. *
  594. * @return int|null Maximum number of results.
  595. */
  596. public function getMaxResults(): ?int
  597. {
  598. return $this->maxResults;
  599. }
  600. /**
  601. * Executes the query and returns an IterableResult that can be used to incrementally
  602. * iterated over the result.
  603. *
  604. * @deprecated
  605. *
  606. * @param ArrayCollection|mixed[]|null $parameters The query parameters.
  607. * @param string|int $hydrationMode The hydration mode to use.
  608. * @psalm-param ArrayCollection<int, Parameter>|array<string, mixed>|null $parameters
  609. * @psalm-param string|AbstractQuery::HYDRATE_*|null $hydrationMode
  610. */
  611. public function iterate($parameters = null, $hydrationMode = self::HYDRATE_OBJECT): IterableResult
  612. {
  613. $this->setHint(self::HINT_INTERNAL_ITERATION, true);
  614. return parent::iterate($parameters, $hydrationMode);
  615. }
  616. /** {@inheritDoc} */
  617. public function toIterable(iterable $parameters = [], $hydrationMode = self::HYDRATE_OBJECT): iterable
  618. {
  619. $this->setHint(self::HINT_INTERNAL_ITERATION, true);
  620. return parent::toIterable($parameters, $hydrationMode);
  621. }
  622. /**
  623. * {@inheritDoc}
  624. */
  625. public function setHint($name, $value): self
  626. {
  627. $this->state = self::STATE_DIRTY;
  628. return parent::setHint($name, $value);
  629. }
  630. /**
  631. * {@inheritDoc}
  632. */
  633. public function setHydrationMode($hydrationMode): self
  634. {
  635. $this->state = self::STATE_DIRTY;
  636. return parent::setHydrationMode($hydrationMode);
  637. }
  638. /**
  639. * Set the lock mode for this Query.
  640. *
  641. * @see \Doctrine\DBAL\LockMode
  642. *
  643. * @param int $lockMode
  644. * @psalm-param LockMode::* $lockMode
  645. *
  646. * @return $this
  647. *
  648. * @throws TransactionRequiredException
  649. */
  650. public function setLockMode($lockMode): self
  651. {
  652. if (in_array($lockMode, [LockMode::NONE, LockMode::PESSIMISTIC_READ, LockMode::PESSIMISTIC_WRITE], true)) {
  653. if (! $this->_em->getConnection()->isTransactionActive()) {
  654. throw TransactionRequiredException::transactionRequired();
  655. }
  656. }
  657. $this->setHint(self::HINT_LOCK_MODE, $lockMode);
  658. return $this;
  659. }
  660. /**
  661. * Get the current lock mode for this query.
  662. *
  663. * @return int|null The current lock mode of this query or NULL if no specific lock mode is set.
  664. */
  665. public function getLockMode(): ?int
  666. {
  667. $lockMode = $this->getHint(self::HINT_LOCK_MODE);
  668. if ($lockMode === false) {
  669. return null;
  670. }
  671. return $lockMode;
  672. }
  673. /**
  674. * Generate a cache id for the query cache - reusing the Result-Cache-Id generator.
  675. */
  676. protected function getQueryCacheId(): string
  677. {
  678. ksort($this->_hints);
  679. return md5(
  680. $this->getDQL() . serialize($this->_hints) .
  681. '&platform=' . get_debug_type($this->getEntityManager()->getConnection()->getDatabasePlatform()) .
  682. ($this->_em->hasFilters() ? $this->_em->getFilters()->getHash() : '') .
  683. '&firstResult=' . $this->firstResult . '&maxResult=' . $this->maxResults .
  684. '&hydrationMode=' . $this->_hydrationMode . '&types=' . serialize($this->parsedTypes) . 'DOCTRINE_QUERY_CACHE_SALT'
  685. );
  686. }
  687. protected function getHash(): string
  688. {
  689. return sha1(parent::getHash() . '-' . $this->firstResult . '-' . $this->maxResults);
  690. }
  691. /**
  692. * Cleanup Query resource when clone is called.
  693. */
  694. public function __clone()
  695. {
  696. parent::__clone();
  697. $this->state = self::STATE_DIRTY;
  698. }
  699. }