1
0
mirror of synced 2025-02-06 23:39:25 +03:00

[DDC-551] Fixed CS, comments by @stof

This commit is contained in:
Alexander 2011-12-05 23:00:52 +01:00
parent f4663f4512
commit efe7a01482
9 changed files with 50 additions and 48 deletions

View File

@ -804,7 +804,7 @@ class EntityManager implements ObjectManager
*/ */
public function getFilters() public function getFilters()
{ {
if(null === $this->filterCollection) { if (null === $this->filterCollection) {
$this->filterCollection = new FilterCollection($this); $this->filterCollection = new FilterCollection($this);
} }
@ -814,7 +814,7 @@ class EntityManager implements ObjectManager
/** /**
* Checks whether the state of the filter collection is clean. * Checks whether the state of the filter collection is clean.
* *
* @return boolean True, iff the filter collection is clean. * @return boolean True, if the filter collection is clean.
*/ */
public function isFiltersStateClean() public function isFiltersStateClean()
{ {
@ -825,7 +825,7 @@ class EntityManager implements ObjectManager
/** /**
* Checks whether the Entity Manager has filters. * Checks whether the Entity Manager has filters.
* *
* @return True, iff the EM has a filter collection. * @return True, if the EM has a filter collection.
*/ */
public function hasFilters() public function hasFilters()
{ {

View File

@ -903,8 +903,11 @@ class BasicEntityPersister
$alias = $this->_getSQLTableAlias($this->_class->name); $alias = $this->_getSQLTableAlias($this->_class->name);
if('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { if ('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) {
if($conditionSql) $conditionSql .= ' AND '; if ($conditionSql) {
$conditionSql .= ' AND ';
}
$conditionSql .= $filterSql; $conditionSql .= $filterSql;
} }
@ -1033,7 +1036,7 @@ class BasicEntityPersister
} }
// Add filter SQL // Add filter SQL
if('' !== $filterSql = $this->generateFilterConditionSQL($eagerEntity, $tableAlias)) { if ('' !== $filterSql = $this->generateFilterConditionSQL($eagerEntity, $tableAlias)) {
$this->_selectJoinSql .= ' AND ' . $filterSql; $this->_selectJoinSql .= ' AND ' . $filterSql;
} }
} else { } else {
@ -1541,7 +1544,7 @@ class BasicEntityPersister
. $this->getLockTablesSql($alias) . $this->getLockTablesSql($alias)
. ' WHERE ' . $this->_getSelectConditionSQL($criteria); . ' WHERE ' . $this->_getSelectConditionSQL($criteria);
if('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) { if ('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $alias)) {
$sql .= ' AND ' . $filterSql; $sql .= ' AND ' . $filterSql;
} }
@ -1559,8 +1562,8 @@ class BasicEntityPersister
protected function getJoinSQLForJoinColumns($joinColumns) protected function getJoinSQLForJoinColumns($joinColumns)
{ {
// if one of the join columns is nullable, return left join // if one of the join columns is nullable, return left join
foreach($joinColumns as $joinColumn) { foreach ($joinColumns as $joinColumn) {
if(isset($joinColumn['nullable']) && $joinColumn['nullable']){ if (isset($joinColumn['nullable']) && $joinColumn['nullable']) {
return 'LEFT JOIN'; return 'LEFT JOIN';
} }
} }
@ -1595,8 +1598,8 @@ class BasicEntityPersister
{ {
$filterClauses = array(); $filterClauses = array();
foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) {
if('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) {
$filterClauses[] = '(' . $filterExpr . ')'; $filterClauses[] = '(' . $filterExpr . ')';
} }
} }

View File

@ -329,9 +329,9 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn; $joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn;
if($parentClass->name === $this->_class->rootEntityName) { if ($parentClass->name === $this->_class->rootEntityName) {
// Add filters on the root class // Add filters on the root class
if('' !== $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) { if ('' !== $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) {
$joinSql .= ' AND ' . $filterSql; $joinSql .= ' AND ' . $filterSql;
} }
} }
@ -383,9 +383,12 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
$conditionSql = $this->_getSelectConditionSQL($criteria, $assoc); $conditionSql = $this->_getSelectConditionSQL($criteria, $assoc);
// If the current class in the root entity, add the filters // If the current class in the root entity, add the filters
if($this->_class->name === $this->_class->rootEntityName) { if ($this->_class->name === $this->_class->rootEntityName) {
if('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias)) { if ('' !== $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias)) {
if($conditionSql) $conditionSql .= ' AND '; if ($conditionSql) {
$conditionSql .= ' AND ';
}
$conditionSql .= $filterSql; $conditionSql .= $filterSql;
} }
} }

View File

@ -219,7 +219,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
} }
list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping); list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping);
if('' !== $filterSql) { if ('' !== $filterSql) {
$whereClauses[] = $filterSql; $whereClauses[] = $filterSql;
} }
@ -331,9 +331,9 @@ class ManyToManyPersister extends AbstractCollectionPersister
: $sourceId[$sourceClass->fieldNames[$mapping['relationToSourceKeyColumns'][$joinTableColumn]]]; : $sourceId[$sourceClass->fieldNames[$mapping['relationToSourceKeyColumns'][$joinTableColumn]]];
} }
if($addFilters) { if ($addFilters) {
list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping); list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping);
if('' !== $filterSql) { if ('' !== $filterSql) {
$quotedJoinTable .= ' t ' . $joinTargetEntitySQL; $quotedJoinTable .= ' t ' . $joinTargetEntitySQL;
$whereClauses[] = $filterSql; $whereClauses[] = $filterSql;
} }
@ -355,13 +355,13 @@ class ManyToManyPersister extends AbstractCollectionPersister
// A join is needed if there is filtering on the target entity // A join is needed if there is filtering on the target entity
$joinTargetEntitySQL = ''; $joinTargetEntitySQL = '';
if('' !== $filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) { if ('' !== $filterSql = $this->generateFilterConditionSQL($targetClass, 'te')) {
$joinTargetEntitySQL = ' JOIN ' $joinTargetEntitySQL = ' JOIN '
. $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' te' . $targetClass->getQuotedTableName($this->_conn->getDatabasePlatform()) . ' te'
. ' ON'; . ' ON';
$joinTargetEntitySQLClauses = array(); $joinTargetEntitySQLClauses = array();
foreach($mapping['relationToTargetKeyColumns'] as $joinTableColumn => $targetTableColumn) { foreach ($mapping['relationToTargetKeyColumns'] as $joinTableColumn => $targetTableColumn) {
$joinTargetEntitySQLClauses[] = ' t.' . $joinTableColumn . ' = ' . 'te.' . $targetTableColumn; $joinTargetEntitySQLClauses[] = ' t.' . $joinTableColumn . ' = ' . 'te.' . $targetTableColumn;
} }
@ -383,8 +383,8 @@ class ManyToManyPersister extends AbstractCollectionPersister
{ {
$filterClauses = array(); $filterClauses = array();
foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) {
if('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) {
$filterClauses[] = '(' . $filterExpr . ')'; $filterClauses[] = '(' . $filterExpr . ')';
} }
} }

View File

@ -121,8 +121,8 @@ class OneToManyPersister extends AbstractCollectionPersister
: $id[$sourceClass->fieldNames[$joinColumn['referencedColumnName']]]; : $id[$sourceClass->fieldNames[$joinColumn['referencedColumnName']]];
} }
foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) {
if("" !== $filterExpr = $filter->addFilterConstraint($targetClass, 't')) { if ('' !== $filterExpr = $filter->addFilterConstraint($targetClass, 't')) {
$whereClauses[] = '(' . $filterExpr . ')'; $whereClauses[] = '(' . $filterExpr . ')';
} }
} }

View File

@ -138,7 +138,7 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
{ {
// Ensure that the filters are applied to the root entity of the inheritance tree // Ensure that the filters are applied to the root entity of the inheritance tree
$realTargetEntity = $targetEntity; $realTargetEntity = $targetEntity;
if($targetEntity->name !== $targetEntity->rootEntityName) { if ($targetEntity->name !== $targetEntity->rootEntityName) {
$realTargetEntity = $this->_em->getClassMetadata($targetEntity->rootEntityName); $realTargetEntity = $this->_em->getClassMetadata($targetEntity->rootEntityName);
} }

View File

@ -49,7 +49,6 @@ abstract class SQLFilter
* Constructs the SQLFilter object. * Constructs the SQLFilter object.
* *
* @param EntityManager $em The EM * @param EntityManager $em The EM
* @final
*/ */
final public function __construct(EntityManager $em) final public function __construct(EntityManager $em)
{ {
@ -63,7 +62,6 @@ abstract class SQLFilter
* @param string $value Value of the parameter. * @param string $value Value of the parameter.
* @param string $type Type of the parameter. * @param string $type Type of the parameter.
* *
* @final
* @return SQLFilter The current SQL filter. * @return SQLFilter The current SQL filter.
*/ */
final public function setParameter($name, $value, $type) final public function setParameter($name, $value, $type)
@ -88,12 +86,11 @@ abstract class SQLFilter
* *
* @param string $name Name of the parameter. * @param string $name Name of the parameter.
* *
* @final
* @return string The SQL escaped parameter to use in a query. * @return string The SQL escaped parameter to use in a query.
*/ */
final public function getParameter($name) final public function getParameter($name)
{ {
if(!isset($this->parameters[$name])) { if (!isset($this->parameters[$name])) {
throw new \InvalidArgumentException("Parameter '" . $name . "' does not exist."); throw new \InvalidArgumentException("Parameter '" . $name . "' does not exist.");
} }
@ -103,8 +100,7 @@ abstract class SQLFilter
/** /**
* Returns as string representation of the SQLFilter parameters (the state). * Returns as string representation of the SQLFilter parameters (the state).
* *
* @final * @return string String representation of the SQLFilter.
* @return string String representation of the the SQLFilter.
*/ */
final public function __toString() final public function __toString()
{ {

View File

@ -103,11 +103,11 @@ class FilterCollection
*/ */
public function enable($name) public function enable($name)
{ {
if(null === $filterClass = $this->config->getFilterClassName($name)) { if (null === $filterClass = $this->config->getFilterClassName($name)) {
throw new \InvalidArgumentException("Filter '" . $name . "' does not exist."); throw new \InvalidArgumentException("Filter '" . $name . "' does not exist.");
} }
if(!isset($this->enabledFilters[$name])) { if (!isset($this->enabledFilters[$name])) {
$this->enabledFilters[$name] = new $filterClass($this->em); $this->enabledFilters[$name] = new $filterClass($this->em);
// Keep the enabled filters sorted for the hash // Keep the enabled filters sorted for the hash
@ -153,7 +153,7 @@ class FilterCollection
*/ */
public function getFilter($name) public function getFilter($name)
{ {
if(!isset($this->enabledFilters[$name])) { if (!isset($this->enabledFilters[$name])) {
throw new \InvalidArgumentException("Filter '" . $name . "' is not enabled."); throw new \InvalidArgumentException("Filter '" . $name . "' is not enabled.");
} }
@ -176,12 +176,12 @@ class FilterCollection
public function getHash() public function getHash()
{ {
// If there are only clean filters, the previous hash can be returned // If there are only clean filters, the previous hash can be returned
if(self::FILTERS_STATE_CLEAN === $this->filtersState) { if (self::FILTERS_STATE_CLEAN === $this->filtersState) {
return $this->filterHash; return $this->filterHash;
} }
$filterHash = ''; $filterHash = '';
foreach($this->enabledFilters as $name => $filter) { foreach ($this->enabledFilters as $name => $filter) {
$filterHash .= $name . $filter; $filterHash .= $name . $filter;
} }

View File

@ -365,9 +365,9 @@ class SqlWalker implements TreeWalker
{ {
$filterClauses = array(); $filterClauses = array();
if($this->_em->hasFilters()) { if ($this->_em->hasFilters()) {
foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { foreach ($this->_em->getFilters()->getEnabledFilters() as $filter) {
if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) {
$filterClauses[] = '(' . $filterExpr . ')'; $filterClauses[] = '(' . $filterExpr . ')';
} }
} }
@ -827,9 +827,8 @@ class SqlWalker implements TreeWalker
} }
// Apply the filters // Apply the filters
if("" !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { if ('' !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) {
if ( ! $first) $sql .= ' AND '; else $first = false; $sql .= ' AND ' . $filterExpr;
$sql .= $filterExpr;
} }
} else if ($assoc['type'] == ClassMetadata::MANY_TO_MANY) { } else if ($assoc['type'] == ClassMetadata::MANY_TO_MANY) {
// Join relation table // Join relation table
@ -896,9 +895,8 @@ class SqlWalker implements TreeWalker
} }
// Apply the filters // Apply the filters
if("" !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) { if ('' !== $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias)) {
if ( ! $first) $sql .= ' AND '; else $first = false; $sql .= ' AND ' . $filterExpr;
$sql .= $filterExpr;
} }
} }
@ -1508,13 +1506,15 @@ class SqlWalker implements TreeWalker
$class = $this->_queryComponents[$dqlAlias]['metadata']; $class = $this->_queryComponents[$dqlAlias]['metadata'];
$tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias);
if("" !== $filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) { if ('' !== $filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) {
$filterClauses[] = $filterExpr; $filterClauses[] = $filterExpr;
} }
} }
if (count($filterClauses)) { if (count($filterClauses)) {
if($condSql) $condSql .= ' AND '; if ($condSql) {
$condSql .= ' AND ';
}
$condSql .= implode(' AND ', $filterClauses); $condSql .= implode(' AND ', $filterClauses);
} }