1
0
mirror of synced 2025-02-06 15:29:26 +03:00

Coding style fixes.

This commit is contained in:
Guilherme Blanco 2012-03-15 01:26:06 -04:00
parent a16ca32981
commit 44d7d23e8d
3 changed files with 42 additions and 43 deletions

View File

@ -33,7 +33,6 @@ use Doctrine\DBAL\LockMode,
*/ */
final class Query extends AbstractQuery final class Query extends AbstractQuery
{ {
/* Query STATES */
/** /**
* A query object is in CLEAN state when it has NO unparsed/unprocessed DQL parts. * A query object is in CLEAN state when it has NO unparsed/unprocessed DQL parts.
*/ */
@ -108,6 +107,7 @@ final class Query extends AbstractQuery
*/ */
const HINT_LOCK_MODE = 'doctrine.lockMode'; const HINT_LOCK_MODE = 'doctrine.lockMode';
/** /**
* @var integer $_state The current state of this query. * @var integer $_state The current state of this query.
*/ */
@ -153,8 +153,6 @@ final class Query extends AbstractQuery
*/ */
private $_useQueryCache = true; private $_useQueryCache = true;
// End of Caching Stuff
/** /**
* Initializes a new Query instance. * Initializes a new Query instance.
* *
@ -186,6 +184,7 @@ final class Query extends AbstractQuery
public function getAST() public function getAST()
{ {
$parser = new Parser($this); $parser = new Parser($this);
return $parser->getAST(); return $parser->getAST();
} }
@ -199,9 +198,7 @@ final class Query extends AbstractQuery
private function _parse() private function _parse()
{ {
// Return previous parser result if the query and the filter collection are both clean // Return previous parser result if the query and the filter collection are both clean
if ($this->_state === self::STATE_CLEAN if ($this->_state === self::STATE_CLEAN && $this->_em->isFiltersStateClean()) {
&& $this->_em->isFiltersStateClean()
) {
return $this->_parserResult; return $this->_parserResult;
} }
@ -210,6 +207,7 @@ final class Query extends AbstractQuery
// Check query cache. // Check query cache.
if ( ! ($this->_useQueryCache && ($queryCache = $this->getQueryCacheDriver()))) { if ( ! ($this->_useQueryCache && ($queryCache = $this->getQueryCacheDriver()))) {
$parser = new Parser($this); $parser = new Parser($this);
$this->_parserResult = $parser->parse(); $this->_parserResult = $parser->parse();
return $this->_parserResult; return $this->_parserResult;
@ -227,7 +225,9 @@ final class Query extends AbstractQuery
// Cache miss. // Cache miss.
$parser = new Parser($this); $parser = new Parser($this);
$this->_parserResult = $parser->parse(); $this->_parserResult = $parser->parse();
$queryCache->save($hash, $this->_parserResult, $this->_queryCacheTTL); $queryCache->save($hash, $this->_parserResult, $this->_queryCacheTTL);
return $this->_parserResult; return $this->_parserResult;
@ -282,7 +282,9 @@ final class Query extends AbstractQuery
} }
$sqlPositions = $paramMappings[$key]; $sqlPositions = $paramMappings[$key];
// optimized multi value sql positions away for now, they are not allowed in DQL anyways.
// optimized multi value sql positions away for now,
// they are not allowed in DQL anyways.
$value = array($value); $value = array($value);
$countValue = count($value); $countValue = count($value);
@ -469,7 +471,7 @@ final class Query extends AbstractQuery
public function setFirstResult($firstResult) public function setFirstResult($firstResult)
{ {
$this->_firstResult = $firstResult; $this->_firstResult = $firstResult;
$this->_state = self::STATE_DIRTY; $this->_state = self::STATE_DIRTY;
return $this; return $this;
} }
@ -494,7 +496,7 @@ final class Query extends AbstractQuery
public function setMaxResults($maxResults) public function setMaxResults($maxResults)
{ {
$this->_maxResults = $maxResults; $this->_maxResults = $maxResults;
$this->_state = self::STATE_DIRTY; $this->_state = self::STATE_DIRTY;
return $this; return $this;
} }
@ -554,7 +556,7 @@ final class Query extends AbstractQuery
*/ */
public function setLockMode($lockMode) public function setLockMode($lockMode)
{ {
if ($lockMode === LockMode::PESSIMISTIC_READ || $lockMode === LockMode::PESSIMISTIC_WRITE) { if (in_array($lockMode, array(LockMode::PESSIMISTIC_READ, LockMode::PESSIMISTIC_WRITE))) {
if ( ! $this->_em->getConnection()->isTransactionActive()) { if ( ! $this->_em->getConnection()->isTransactionActive()) {
throw TransactionRequiredException::transactionRequired(); throw TransactionRequiredException::transactionRequired();
} }

View File

@ -193,7 +193,7 @@ class QueryBuilder
} }
$this->_state = self::STATE_CLEAN; $this->_state = self::STATE_CLEAN;
$this->_dql = $dql; $this->_dql = $dql;
return $dql; return $dql;
} }
@ -214,9 +214,9 @@ class QueryBuilder
public function getQuery() public function getQuery()
{ {
return $this->_em->createQuery($this->getDQL()) return $this->_em->createQuery($this->getDQL())
->setParameters($this->_params, $this->_paramTypes) ->setParameters($this->_params, $this->_paramTypes)
->setFirstResult($this->_firstResult) ->setFirstResult($this->_firstResult)
->setMaxResults($this->_maxResults); ->setMaxResults($this->_maxResults);
} }
/** /**
@ -225,8 +225,8 @@ class QueryBuilder
* *
* <code> * <code>
* $qb = $em->createQueryBuilder() * $qb = $em->createQueryBuilder()
* ->select('u') * ->select('u')
* ->from('User', 'u'); * ->from('User', 'u');
* *
* echo $qb->getRootAlias(); // u * echo $qb->getRootAlias(); // u
* </code> * </code>
@ -326,12 +326,8 @@ class QueryBuilder
{ {
$key = trim($key, ':'); $key = trim($key, ':');
if ($type === null) { $this->_paramTypes[$key] = $type ?: Query\ParameterTypeInferer::inferType($value);
$type = Query\ParameterTypeInferer::inferType($value); $this->_params[$key] = $value;
}
$this->_paramTypes[$key] = $type;
$this->_params[$key] = $value;
return $this; return $this;
} }
@ -450,13 +446,13 @@ class QueryBuilder
// TODO: Remove for 3.0 // TODO: Remove for 3.0
if ($dqlPartName == 'join') { if ($dqlPartName == 'join') {
$newDqlPart = array(); $newDqlPart = array();
foreach ($dqlPart AS $k => $v) { foreach ($dqlPart AS $k => $v) {
if (is_numeric($k)) { $k = is_numeric($k) ? $this->getRootAlias() : $k;
$newDqlPart[$this->getRootAlias()] = $v;
} else { $newDqlPart[$k] = $v;
$newDqlPart[$k] = $v;
}
} }
$dqlPart = $newDqlPart; $dqlPart = $newDqlPart;
} }
@ -520,6 +516,7 @@ class QueryBuilder
public function distinct($flag = true) public function distinct($flag = true)
{ {
$this->_dqlParts['distinct'] = (bool) $flag; $this->_dqlParts['distinct'] = (bool) $flag;
return $this; return $this;
} }
@ -791,7 +788,7 @@ class QueryBuilder
public function andWhere($where) public function andWhere($where)
{ {
$where = $this->getDQLPart('where'); $where = $this->getDQLPart('where');
$args = func_get_args(); $args = func_get_args();
if ($where instanceof Expr\Andx) { if ($where instanceof Expr\Andx) {
$where->addMultiple($args); $where->addMultiple($args);
@ -822,7 +819,7 @@ class QueryBuilder
public function orWhere($where) public function orWhere($where)
{ {
$where = $this->getDqlPart('where'); $where = $this->getDqlPart('where');
$args = func_get_args(); $args = func_get_args();
if ($where instanceof Expr\Orx) { if ($where instanceof Expr\Orx) {
$where->addMultiple($args); $where->addMultiple($args);
@ -899,7 +896,7 @@ class QueryBuilder
public function andHaving($having) public function andHaving($having)
{ {
$having = $this->getDqlPart('having'); $having = $this->getDqlPart('having');
$args = func_get_args(); $args = func_get_args();
if ($having instanceof Expr\Andx) { if ($having instanceof Expr\Andx) {
$having->addMultiple($args); $having->addMultiple($args);
@ -921,7 +918,7 @@ class QueryBuilder
public function orHaving($having) public function orHaving($having)
{ {
$having = $this->getDqlPart('having'); $having = $this->getDqlPart('having');
$args = func_get_args(); $args = func_get_args();
if ($having instanceof Expr\Orx) { if ($having instanceof Expr\Orx) {
$having->addMultiple($args); $having->addMultiple($args);
@ -943,8 +940,9 @@ class QueryBuilder
*/ */
public function orderBy($sort, $order = null) public function orderBy($sort, $order = null)
{ {
return $this->add('orderBy', $sort instanceof Expr\OrderBy ? $sort $orderBy = ($sort instanceof Expr\OrderBy) ? $sort : new Expr\OrderBy($sort, $order);
: new Expr\OrderBy($sort, $order));
return $this->add('orderBy', $orderBy);
} }
/** /**
@ -1002,8 +1000,8 @@ class QueryBuilder
private function _getDQLForSelect() private function _getDQLForSelect()
{ {
$dql = 'SELECT' $dql = 'SELECT'
. ($this->_dqlParts['distinct']===true ? ' DISTINCT' : '') . ($this->_dqlParts['distinct']===true ? ' DISTINCT' : '')
. $this->_getReducedDQLQueryPart('select', array('pre' => ' ', 'separator' => ', ')); . $this->_getReducedDQLQueryPart('select', array('pre' => ' ', 'separator' => ', '));
$fromParts = $this->getDQLPart('from'); $fromParts = $this->getDQLPart('from');
$joinParts = $this->getDQLPart('join'); $joinParts = $this->getDQLPart('join');
@ -1059,9 +1057,11 @@ class QueryBuilder
if (is_null($parts)) { if (is_null($parts)) {
$parts = array_keys($this->_dqlParts); $parts = array_keys($this->_dqlParts);
} }
foreach ($parts as $part) { foreach ($parts as $part) {
$this->resetDQLPart($part); $this->resetDQLPart($part);
} }
return $this; return $this;
} }
@ -1073,12 +1073,9 @@ class QueryBuilder
*/ */
public function resetDQLPart($part) public function resetDQLPart($part)
{ {
if (is_array($this->_dqlParts[$part])) { $this->_dqlParts[$part] = is_array($this->_dqlParts[$part]) ? array() : null;
$this->_dqlParts[$part] = array(); $this->_state = self::STATE_DIRTY;
} else {
$this->_dqlParts[$part] = null;
}
$this->_state = self::STATE_DIRTY;
return $this; return $this;
} }
@ -1107,7 +1104,7 @@ class QueryBuilder
$this->_dqlParts[$part][$idx] = clone $element; $this->_dqlParts[$part][$idx] = clone $element;
} }
} }
} else if (\is_object($elements)) { } else if (is_object($elements)) {
$this->_dqlParts[$part] = clone $elements; $this->_dqlParts[$part] = clone $elements;
} }
} }

View File

@ -48,7 +48,7 @@ class Version
public static function compare($version) public static function compare($version)
{ {
$currentVersion = str_replace(' ', '', strtolower(self::VERSION)); $currentVersion = str_replace(' ', '', strtolower(self::VERSION));
$version = str_replace(' ', '', $version); $version = str_replace(' ', '', $version);
return version_compare($version, $currentVersion); return version_compare($version, $currentVersion);
} }