161 lines
5.2 KiB
PHP
161 lines
5.2 KiB
PHP
<?php
|
|
/*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
* This software consists of voluntary contributions made by many individuals
|
|
* and is licensed under the MIT license. For more information, see
|
|
* <http://www.doctrine-project.org>.
|
|
*/
|
|
|
|
namespace Doctrine\ORM\Mapping;
|
|
|
|
|
|
/**
|
|
* A set of rules for determining the physical column, alias and table quotes
|
|
*
|
|
* @since 2.3
|
|
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
|
*/
|
|
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);
|
|
}
|
|
|
|
} |