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

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