2012-05-11 04:18:09 +04:00
|
|
|
<?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
|
2012-06-04 22:16:20 +04:00
|
|
|
* and is licensed under the MIT license. For more information, see
|
2012-05-11 04:18:09 +04:00
|
|
|
* <http://www.doctrine-project.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Doctrine\ORM\Mapping;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A set of rules for determining the physical column, alias and table quotes
|
|
|
|
*
|
2012-06-04 23:56:46 +04:00
|
|
|
* @since 2.3
|
2012-05-11 04:18:09 +04:00
|
|
|
* @author Fabio B. Silva <fabio.bat.silva@gmail.com>
|
|
|
|
*/
|
|
|
|
class DefaultQuoteStrategy extends QuoteStrategy
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2012-06-01 01:37:51 +04:00
|
|
|
* {@inheritdoc}
|
2012-05-11 04:18:09 +04:00
|
|
|
*/
|
|
|
|
public function getColumnName($fieldName, ClassMetadata $class)
|
|
|
|
{
|
|
|
|
return isset($class->fieldMappings[$fieldName]['quoted'])
|
|
|
|
? $this->platform->quoteIdentifier($class->fieldMappings[$fieldName]['columnName'])
|
|
|
|
: $class->fieldMappings[$fieldName]['columnName'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-01 01:37:51 +04:00
|
|
|
* {@inheritdoc}
|
2012-05-11 04:18:09 +04:00
|
|
|
*/
|
|
|
|
public function getTableName(ClassMetadata $class)
|
|
|
|
{
|
|
|
|
return isset($class->table['quoted'])
|
|
|
|
? $this->platform->quoteIdentifier($class->table['name'])
|
|
|
|
: $class->table['name'];
|
|
|
|
}
|
|
|
|
|
2012-06-06 00:10:44 +04:00
|
|
|
/**
|
|
|
|
* {@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)
|
|
|
|
{
|
2012-06-06 20:14:20 +04:00
|
|
|
if( ! isset($association['joinColumns'])) {
|
2012-06-06 00:10:44 +04:00
|
|
|
return $columnName;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($association['joinColumns'] as $joinColumn) {
|
|
|
|
if($joinColumn['name'] === $columnName) {
|
|
|
|
if (isset($joinColumn['quoted'])) {
|
|
|
|
return $this->platform->quoteIdentifier($columnName);
|
|
|
|
}
|
|
|
|
return $columnName;
|
|
|
|
}
|
|
|
|
}
|
2012-06-06 20:14:20 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-06-06 00:10:44 +04:00
|
|
|
|
|
|
|
return $columnName;
|
|
|
|
}
|
|
|
|
|
2012-05-11 04:18:09 +04:00
|
|
|
/**
|
2012-06-01 01:37:51 +04:00
|
|
|
* {@inheritdoc}
|
2012-05-11 04:18:09 +04:00
|
|
|
*/
|
2012-06-01 02:10:34 +04:00
|
|
|
public function getJoinTableName(array $association, ClassMetadata $class)
|
2012-05-11 04:18:09 +04:00
|
|
|
{
|
2012-06-01 02:10:34 +04:00
|
|
|
return isset($association['joinTable']['quoted'])
|
|
|
|
? $this->platform->quoteIdentifier($association['joinTable']['name'])
|
|
|
|
: $association['joinTable']['name'];
|
2012-05-11 04:18:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-01 01:37:51 +04:00
|
|
|
* {@inheritdoc}
|
2012-05-11 04:18:09 +04:00
|
|
|
*/
|
|
|
|
public function getIdentifierColumnNames(ClassMetadata $class)
|
|
|
|
{
|
|
|
|
$quotedColumnNames = array();
|
|
|
|
|
|
|
|
foreach ($class->identifier as $fieldName) {
|
2012-05-30 22:28:03 +04:00
|
|
|
if (isset($class->fieldMappings[$fieldName])) {
|
2012-05-11 04:18:09 +04:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-01 01:37:51 +04:00
|
|
|
* {@inheritdoc}
|
2012-05-11 04:18:09 +04:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|