当前位置: 首页>>代码示例>>PHP>>正文


PHP Parser::parse方法代码示例

本文整理汇总了PHP中Doctrine\ORM\Query\Parser::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::parse方法的具体用法?PHP Parser::parse怎么用?PHP Parser::parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\Query\Parser的用法示例。


在下文中一共展示了Parser::parse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getCount

 /**
  * Calculates total count of query records
  *
  * @param Query $query
  * @param \Doctrine\Common\Collections\ArrayCollection|array|null $parameters Query parameters.
  * @return integer
  */
 public function getCount(Query $query, $parameters = null)
 {
     if (!empty($parameters)) {
         $query = clone $query;
         $query->setParameters($parameters);
     }
     $parser = new Parser($query);
     $parserResult = $parser->parse();
     $parameterMappings = $parserResult->getParameterMappings();
     list($sqlParameters, $parameterTypes) = $this->processParameterMappings($query, $parameterMappings);
     $statement = $query->getEntityManager()->getConnection()->executeQuery('SELECT COUNT(*) FROM (' . $query->getSQL() . ') AS e', $sqlParameters, $parameterTypes);
     $result = $statement->fetchColumn();
     return $result ? (int) $result : 0;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:21,代码来源:QueryCountCalculator.php

示例2: processParameterMappings

 /**
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * Copy of Doctrine\ORM\Query::processParameterMappings
  *
  * @param Query $query
  * @return array
  * @throws QueryException
  */
 public function processParameterMappings(Query $query)
 {
     $parser = new Parser($query);
     $parseResult = $parser->parse();
     $paramMappings = $parseResult->getParameterMappings();
     $resultSetMapping = $parseResult->getResultSetMapping();
     $paramCount = count($query->getParameters());
     $mappingCount = count($paramMappings);
     if ($paramCount > $mappingCount) {
         throw QueryException::tooManyParameters($mappingCount, $paramCount);
     } elseif ($paramCount < $mappingCount) {
         throw QueryException::tooFewParameters($mappingCount, $paramCount);
     }
     $sqlParams = [];
     $types = [];
     foreach ($query->getParameters() as $parameter) {
         $key = $parameter->getName();
         $value = $parameter->getValue();
         $rsm = $resultSetMapping;
         if (!isset($paramMappings[$key])) {
             throw QueryException::unknownParameter($key);
         }
         if (isset($rsm->metadataParameterMapping[$key]) && $value instanceof ClassMetadata) {
             $value = $value->getMetadataValue($rsm->metadataParameterMapping[$key]);
         }
         $value = $query->processParameterValue($value);
         $type = $parameter->getValue() === $value ? $parameter->getType() : Query\ParameterTypeInferer::inferType($value);
         foreach ($paramMappings[$key] as $position) {
             $types[$position] = $type;
         }
         $sqlPositions = $paramMappings[$key];
         // optimized multi value sql positions away for now,
         // they are not allowed in DQL anyways.
         $value = [$value];
         $countValue = count($value);
         for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
             $sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
         }
     }
     if (count($sqlParams) !== count($types)) {
         throw QueryException::parameterTypeMismatch();
     }
     if ($sqlParams) {
         ksort($sqlParams);
         $sqlParams = array_values($sqlParams);
         ksort($types);
         $types = array_values($types);
     }
     return [$sqlParams, $types];
 }
开发者ID:startupz,项目名称:platform-1,代码行数:60,代码来源:NativeQueryExecutorHelper.php

示例3: getCount

 /**
  * Calculates total count of query records
  * Notes: this method do not make any modifications of the given query
  *
  * @param Query $query
  *
  * @return integer
  */
 public function getCount(Query $query)
 {
     if ($this->useWalker($query)) {
         if (!$query->contains('DISTINCT')) {
             $query->setHint(CountWalker::HINT_DISTINCT, false);
         }
         // fix of doctrine count walker bug
         // TODO revert changes when doctrine version >= 2.5 in scope of BAP-5577
         /* @var $countQuery Query */
         $countQuery = clone $query;
         $countQuery->setParameters(clone $query->getParameters());
         foreach ($query->getHints() as $name => $value) {
             $countQuery->setHint($name, $value);
         }
         if (!$countQuery->hasHint(CountWalker::HINT_DISTINCT)) {
             $countQuery->setHint(CountWalker::HINT_DISTINCT, true);
         }
         $this->appendTreeWalker($countQuery, 'Oro\\Bundle\\BatchBundle\\ORM\\Query\\Walker\\CountWalker');
         $countQuery->setFirstResult(null)->setMaxResults(null);
         try {
             $data = $countQuery->getScalarResult();
             $data = array_map('current', $data);
             $result = array_sum($data);
         } catch (NoResultException $e) {
             $result = 0;
         }
     } else {
         $parser = new Parser($query);
         $parserResult = $parser->parse();
         $parameterMappings = $parserResult->getParameterMappings();
         list($sqlParameters, $parameterTypes) = $this->processParameterMappings($query, $parameterMappings);
         $statement = $query->getEntityManager()->getConnection()->executeQuery('SELECT COUNT(*) FROM (' . $query->getSQL() . ') AS e', $sqlParameters, $parameterTypes);
         $result = $statement->fetchColumn();
     }
     return $result ? (int) $result : 0;
 }
开发者ID:xamin123,项目名称:platform,代码行数:44,代码来源:QueryCountCalculator.php

示例4: _parse

 /**
  * Parses the DQL query, if necessary, and stores the parser result.
  *
  * Note: Populates $this->_parserResult as a side-effect.
  *
  * @return \Doctrine\ORM\Query\ParserResult
  */
 private function _parse()
 {
     // Return previous parser result if the query and the filter collection are both clean
     if ($this->_state === self::STATE_CLEAN && $this->_em->isFiltersStateClean()) {
         return $this->_parserResult;
     }
     $this->_state = self::STATE_CLEAN;
     // Check query cache.
     if (!($this->_useQueryCache && ($queryCache = $this->getQueryCacheDriver()))) {
         $parser = new Parser($this);
         $this->_parserResult = $parser->parse();
         return $this->_parserResult;
     }
     $hash = $this->_getQueryCacheId();
     $cached = $this->_expireQueryCache ? false : $queryCache->fetch($hash);
     if ($cached !== false) {
         // Cache hit.
         $this->_parserResult = $cached;
         return $this->_parserResult;
     }
     // Cache miss.
     $parser = new Parser($this);
     $this->_parserResult = $parser->parse();
     $queryCache->save($hash, $this->_parserResult, $this->_queryCacheTTL);
     return $this->_parserResult;
 }
开发者ID:davidbui2,项目名称:doctrine2,代码行数:33,代码来源:Query.php

示例5: _parse

 /**
  * Parses the DQL query, if necessary, and stores the parser result.
  * 
  * Note: Populates $this->_parserResult as a side-effect.
  *
  * @return Doctrine\ORM\Query\ParserResult
  */
 private function _parse()
 {
     if ($this->_state === self::STATE_CLEAN) {
         return $this->_parserResult;
     }
     // Check query cache.
     if ($this->_useQueryCache && ($queryCache = $this->getQueryCacheDriver())) {
         $hash = $this->_getQueryCacheId();
         $cached = $this->_expireQueryCache ? false : $queryCache->fetch($hash);
         if ($cached === false) {
             // Cache miss.
             $parser = new Parser($this);
             $this->_parserResult = $parser->parse();
             $queryCache->save($hash, $this->_parserResult, $this->_queryCacheTTL);
         } else {
             // Cache hit.
             $this->_parserResult = $cached;
         }
     } else {
         $parser = new Parser($this);
         $this->_parserResult = $parser->parse();
     }
     $this->_state = self::STATE_CLEAN;
     return $this->_parserResult;
 }
开发者ID:poulikov,项目名称:readlater,代码行数:32,代码来源:Query.php

示例6: getCountQuery

 /**
  * Returns Query prepared to count.
  *
  * @return Query
  */
 private function getCountQuery()
 {
     /* @var $countQuery Query */
     $countQuery = $this->cloneQuery($this->query);
     if (!$countQuery->hasHint(CountWalker::HINT_DISTINCT)) {
         $countQuery->setHint(CountWalker::HINT_DISTINCT, true);
     }
     if ($this->useOutputWalker($countQuery)) {
         $platform = $countQuery->getEntityManager()->getConnection()->getDatabasePlatform();
         // law of demeter win
         $rsm = new ResultSetMapping();
         $rsm->addScalarResult($platform->getSQLResultCasing('dctrn_count'), 'count');
         $countQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\\ORM\\Tools\\Pagination\\CountOutputWalker');
         $countQuery->setResultSetMapping($rsm);
     } else {
         $this->appendTreeWalker($countQuery, 'Doctrine\\ORM\\Tools\\Pagination\\CountWalker');
     }
     $countQuery->setFirstResult(null)->setMaxResults(null);
     $parser = new Parser($countQuery);
     $parameterMappings = $parser->parse()->getParameterMappings();
     /* @var $parameters \Doctrine\Common\Collections\Collection|\Doctrine\ORM\Query\Parameter[] */
     $parameters = $countQuery->getParameters();
     foreach ($parameters as $key => $parameter) {
         $parameterName = $parameter->getName();
         if (!(isset($parameterMappings[$parameterName]) || array_key_exists($parameterName, $parameterMappings))) {
             unset($parameters[$key]);
         }
     }
     $countQuery->setParameters($parameters);
     return $countQuery;
 }
开发者ID:ratehub,项目名称:doctrine2,代码行数:36,代码来源:Paginator.php

示例7: _parse

 /**
  * Parses the DQL query, if necessary, and stores the parser result.
  *
  * Note: Populates $this->_parserResult as a side-effect.
  *
  * @return \Doctrine\ORM\Query\ParserResult
  */
 private function _parse()
 {
     $types = array();
     foreach ($this->parameters as $parameter) {
         /** @var Query\Parameter $parameter */
         $types[$parameter->getName()] = $parameter->getType();
     }
     // Return previous parser result if the query and the filter collection are both clean
     if ($this->_state === self::STATE_CLEAN && $this->_parsedTypes === $types && $this->_em->isFiltersStateClean()) {
         return $this->_parserResult;
     }
     $this->_state = self::STATE_CLEAN;
     $this->_parsedTypes = $types;
     // Check query cache.
     if (!($this->_useQueryCache && ($queryCache = $this->getQueryCacheDriver()))) {
         $parser = new Parser($this);
         $this->_parserResult = $parser->parse();
         return $this->_parserResult;
     }
     $hash = $this->_getQueryCacheId();
     $cached = $this->_expireQueryCache ? false : $queryCache->fetch($hash);
     if ($cached instanceof ParserResult) {
         // Cache hit.
         $this->_parserResult = $cached;
         return $this->_parserResult;
     }
     // Cache miss.
     $parser = new Parser($this);
     $this->_parserResult = $parser->parse();
     $queryCache->save($hash, $this->_parserResult, $this->_queryCacheTTL);
     return $this->_parserResult;
 }
开发者ID:aschempp,项目名称:doctrine2,代码行数:39,代码来源:Query.php

示例8: parse

 /**
  * Parses the DQL query, if necessary, and stores the parser result.
  * 
  * Note: Populates $this->_parserResult as a side-effect.
  *
  * @return Doctrine\ORM\Query\ParserResult
  */
 public function parse()
 {
     if ($this->_state === self::STATE_DIRTY) {
         $parser = new Parser($this);
         $this->_parserResult = $parser->parse();
         $this->_state = self::STATE_CLEAN;
     }
     return $this->_parserResult;
 }
开发者ID:jackbravo,项目名称:doctrine,代码行数:16,代码来源:Query.php

示例9: parseQuery

 /**
  * @param Query $query
  *
  * @return ParserResult
  */
 public static function parseQuery(Query $query)
 {
     $parser = new Query\Parser($query);
     return $parser->parse();
 }
开发者ID:hugeval,项目名称:platform,代码行数:10,代码来源:QueryUtils.php


注:本文中的Doctrine\ORM\Query\Parser::parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。