. */ namespace Doctrine\ORM\Mapping; /** * A set of rules for determining the physical column, alias and table quotes * * @since 2.3 * @author Fabio B. Silva */ class DefaultQuoteStrategy extends QuoteStrategy { /** * {@inheritdoc} */ public function getColumnName($fieldName, ClassMetadata $class) { return isset($class->fieldMappings[$fieldName]['quoted']) ? $this->platform->quoteIdentifier($class->fieldMappings[$fieldName]['columnName']) : $class->fieldMappings[$fieldName]['columnName']; } /** * {@inheritdoc} */ public function getTableName(ClassMetadata $class) { return isset($class->table['quoted']) ? $this->platform->quoteIdentifier($class->table['name']) : $class->table['name']; } /** * {@inheritdoc} */ public function getSequenceName(array $definition, ClassMetadata $class) { return isset($definition['quoted']) ? $this->platform->quoteSingleIdentifier($definition['sequenceName']) : $definition['sequenceName']; } /** * {@inheritdoc} */ public function getJoinColumnName($columnName, array $association, ClassMetadata $class) { if( ! isset($association['joinColumns'])) { return $columnName; } foreach ($association['joinColumns'] as $joinColumn) { if($joinColumn['name'] === $columnName) { if (isset($joinColumn['quoted'])) { return $this->platform->quoteIdentifier($columnName); } return $columnName; } } return $columnName; } /** * {@inheritdoc} */ public function getReferencedJoinColumnName($columnName, array $association, ClassMetadata $class) { if( ! isset($association['joinColumns'])) { return $columnName; } foreach ($association['joinColumns'] as $joinColumn) { if($joinColumn['referencedColumnName'] === $columnName) { if (isset($joinColumn['quoted'])) { return $this->platform->quoteIdentifier($columnName); } return $columnName; } } return $columnName; } /** * {@inheritdoc} */ public function getJoinTableName(array $association, ClassMetadata $class) { return isset($association['joinTable']['quoted']) ? $this->platform->quoteIdentifier($association['joinTable']['name']) : $association['joinTable']['name']; } /** * {@inheritdoc} */ public function getIdentifierColumnNames(ClassMetadata $class) { $quotedColumnNames = array(); foreach ($class->identifier as $fieldName) { if (isset($class->fieldMappings[$fieldName])) { $quotedColumnNames[] = $this->getColumnName($fieldName, $class); continue; } // Association defined as Id field $platform = $this->platform; $joinColumns = $class->associationMappings[$fieldName]['joinColumns']; $assocQuotedColumnNames = array_map( function ($joinColumn) use ($platform) { return isset($joinColumn['quoted']) ? $platform->quoteIdentifier($joinColumn['name']) : $joinColumn['name']; }, $joinColumns ); $quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames); } return $quotedColumnNames; } /** * {@inheritdoc} */ public function getColumnAlias($columnName, $counter, ClassMetadata $class = null) { // Trim the column alias to the maximum identifier length of the platform. // If the alias is to long, characters are cut off from the beginning. // And strip non alphanumeric characters $columnName = $columnName . $counter; $columnName = substr($columnName, -$this->platform->getMaxIdentifierLength()); $columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName); return $this->platform->getSQLResultCasing($columnName); } }