Exemplo n.º 1
0
 /**
  * Generates a new semantical error.
  *
  * @param string $message Optional message.
  * @param array $token Optional token.
  *
  * @throws \Doctrine\ORM\Query\QueryException
  */
 public function semanticalError($message = '', $token = null)
 {
     if ($token === null) {
         $token = $this->_lexer->lookahead;
     }
     // Minimum exposed chars ahead of token
     $distance = 12;
     // Find a position of a final word to display in error string
     $dql = $this->_query->getDql();
     $length = strlen($dql);
     $pos = $token['position'] + $distance;
     $pos = strpos($dql, ' ', $length > $pos ? $pos : $length);
     $length = $pos !== false ? $pos - $token['position'] : $distance;
     // Building informative message
     $message = 'line 0, col ' . (isset($token['position']) && $token['position'] > 0 ? $token['position'] : '-1') . " near '" . substr($dql, $token['position'], $length) . "': Error: " . $message;
     throw \Doctrine\ORM\Query\QueryException::semanticalError($message);
 }
Exemplo n.º 2
0
 /**
  * Creates a new query parser object.
  *
  * @param Query $query The Query to parse.
  */
 public function __construct(Query $query)
 {
     $this->_query = $query;
     $this->_em = $query->getEntityManager();
     $this->_lexer = new Lexer($query->getDql());
     $this->_parserResult = new ParserResult();
     //$this->_parserResult->setEntityManager($this->_em);
 }
Exemplo n.º 3
0
    /**
     * Generates a new semantical error.
     *
     * @param string     $message Optional message.
     * @param array|null $token   Optional token.
     *
     * @return void
     *
     * @throws \Doctrine\ORM\Query\QueryException
     */
    public function semanticalError($message = '', $token = null)
    {
        if ($token === null) {
            $token = $this->lexer->lookahead;
        }

        // Minimum exposed chars ahead of token
        $distance = 12;

        // Find a position of a final word to display in error string
        $dql    = $this->query->getDql();
        $length = strlen($dql);
        $pos    = $token['position'] + $distance;
        $pos    = strpos($dql, ' ', ($length > $pos) ? $pos : $length);
        $length = ($pos !== false) ? $pos - $token['position'] : $distance;

        $tokenPos = (isset($token['position']) && $token['position'] > 0) ? $token['position'] : '-1';
        $tokenStr = substr($dql, $token['position'], $length);

        // Building informative message
        $message = 'line 0, col ' . $tokenPos . " near '" . $tokenStr . "': Error: " . $message;

        throw QueryException::semanticalError($message, QueryException::dqlError($this->query->getDQL()));
    }
 /**
  * @param Query $query
  *
  * @return string
  */
 public function getQueryCacheKey(Query $query)
 {
     $hints = $query->getHints();
     ksort($hints);
     return md5($query->getDql() . var_export($query->getParameters(), true) . var_export($hints, true) . '&firstResult=' . $query->getFirstResult() . '&maxResult=' . $query->getMaxResults() . '&hydrationMode=' . $query->getHydrationMode());
 }