vendor/doctrine/orm/lib/Doctrine/ORM/Query.php line 330

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