fix CS and use php constants
This commit is contained in:
parent
8bdb713073
commit
1eddb53d6c
@ -23,6 +23,7 @@ use ReflectionClass, ReflectionProperty;
|
|||||||
use Doctrine\Common\Persistence\Mapping\ClassMetadata AS IClassMetadata;
|
use Doctrine\Common\Persistence\Mapping\ClassMetadata AS IClassMetadata;
|
||||||
use Doctrine\ORM\DefaultNamingStrategy;
|
use Doctrine\ORM\DefaultNamingStrategy;
|
||||||
use Doctrine\ORM\NamingStrategy;
|
use Doctrine\ORM\NamingStrategy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
|
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
|
||||||
* of an entity and it's associations.
|
* of an entity and it's associations.
|
||||||
|
@ -30,52 +30,53 @@ namespace Doctrine\ORM;
|
|||||||
*/
|
*/
|
||||||
interface NamingStrategy
|
interface NamingStrategy
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a table name for an entity class
|
* Return a table name for an entity class
|
||||||
*
|
*
|
||||||
* @param string $className The fully-qualified class name
|
* @param string $className The fully-qualified class name
|
||||||
* @return string A table name
|
* @return string A table name
|
||||||
*/
|
*/
|
||||||
function classToTableName($className);
|
function classToTableName($className);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a column name for a property
|
* Return a column name for a property
|
||||||
*
|
*
|
||||||
* @param string $propertyName A property
|
* @param string $propertyName A property
|
||||||
* @return string A column name
|
* @return string A column name
|
||||||
*/
|
*/
|
||||||
function propertyToColumnName($propertyName);
|
function propertyToColumnName($propertyName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the default reference column name
|
* Return the default reference column name
|
||||||
*
|
*
|
||||||
* @return string A column name
|
* @return string A column name
|
||||||
*/
|
*/
|
||||||
function referenceColumnName();
|
function referenceColumnName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a join column name for a property
|
* Return a join column name for a property
|
||||||
*
|
*
|
||||||
* @param string $propertyName A property
|
* @param string $propertyName A property
|
||||||
* @return string A column name
|
* @return string A join column name
|
||||||
*/
|
*/
|
||||||
function joinColumnName($propertyName);
|
function joinColumnName($propertyName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a join table name
|
* Return a join table name
|
||||||
*
|
*
|
||||||
* @param string $sourceEntity
|
* @param string $sourceEntity The source entity
|
||||||
* @param string $targetEntity
|
* @param string $targetEntity The target entity
|
||||||
* @param string $propertyName
|
* @param string $propertyName A property
|
||||||
|
* @return string A join table name
|
||||||
*/
|
*/
|
||||||
function joinTableName($sourceEntity, $targetEntity, $propertyName = null);
|
function joinTableName($sourceEntity, $targetEntity, $propertyName = null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the foreign key column name for the given parameters
|
* Return the foreign key column name for the given parameters
|
||||||
*
|
*
|
||||||
* @param string $entityName
|
* @param string $entityName A entity
|
||||||
* @param string $referencedColumnName
|
* @param string $referencedColumnName A property
|
||||||
|
* @return string A join column name
|
||||||
*/
|
*/
|
||||||
function joinKeyColumnName($entityName, $referencedColumnName = null);
|
function joinKeyColumnName($entityName, $referencedColumnName = null);
|
||||||
}
|
}
|
@ -30,24 +30,23 @@ namespace Doctrine\ORM;
|
|||||||
*/
|
*/
|
||||||
class UnderscoreNamingStrategy implements NamingStrategy
|
class UnderscoreNamingStrategy implements NamingStrategy
|
||||||
{
|
{
|
||||||
const CASE_LOWER = 'lower';
|
|
||||||
const CASE_UPPER = 'upper';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $case;
|
private $case;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $case
|
* Underscore naming strategy construct
|
||||||
|
*
|
||||||
|
* @param integer $case CASE_LOWER | CASE_UPPER
|
||||||
*/
|
*/
|
||||||
public function __construct($case = self::CASE_LOWER)
|
public function __construct($case = CASE_LOWER)
|
||||||
{
|
{
|
||||||
$this->case = $case;
|
$this->case = $case;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function getCase()
|
public function getCase()
|
||||||
{
|
{
|
||||||
@ -55,7 +54,10 @@ class UnderscoreNamingStrategy implements NamingStrategy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $case
|
* Sets string case CASE_LOWER | CASE_UPPER
|
||||||
|
* Alphabetic characters converted to lowercase or uppercase
|
||||||
|
*
|
||||||
|
* @param integer $case
|
||||||
*/
|
*/
|
||||||
public function setCase($case)
|
public function setCase($case)
|
||||||
{
|
{
|
||||||
@ -87,7 +89,7 @@ class UnderscoreNamingStrategy implements NamingStrategy
|
|||||||
*/
|
*/
|
||||||
public function referenceColumnName()
|
public function referenceColumnName()
|
||||||
{
|
{
|
||||||
return $this->case == self::CASE_UPPER ? 'ID' : 'id';
|
return $this->case === CASE_UPPER ? 'ID' : 'id';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,14 +118,14 @@ class UnderscoreNamingStrategy implements NamingStrategy
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $string
|
* @param string $string
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function underscore($string)
|
private function underscore($string)
|
||||||
{
|
{
|
||||||
$string = preg_replace('/(?<=[a-z])([A-Z])/', '_$1', $string);
|
$string = preg_replace('/(?<=[a-z])([A-Z])/', '_$1', $string);
|
||||||
|
|
||||||
if ($this->case == self::CASE_UPPER) {
|
if ($this->case === CASE_UPPER) {
|
||||||
return strtoupper($string);
|
return strtoupper($string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
|
|
||||||
|
|
||||||
$this->assertInstanceOf('Doctrine\ORM\DefaultNamingStrategy', $em->getConfiguration()->getNamingStrategy());
|
$this->assertInstanceOf('Doctrine\ORM\DefaultNamingStrategy', $em->getConfiguration()->getNamingStrategy());
|
||||||
$em->getConfiguration()->setNamingStrategy(new \Doctrine\ORM\UnderscoreNamingStrategy('upper'));
|
$em->getConfiguration()->setNamingStrategy(new \Doctrine\ORM\UnderscoreNamingStrategy(CASE_UPPER));
|
||||||
$this->assertInstanceOf('Doctrine\ORM\UnderscoreNamingStrategy', $em->getConfiguration()->getNamingStrategy());
|
$this->assertInstanceOf('Doctrine\ORM\UnderscoreNamingStrategy', $em->getConfiguration()->getNamingStrategy());
|
||||||
|
|
||||||
$class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
|
$class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
|
||||||
|
@ -298,7 +298,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
*/
|
*/
|
||||||
public function testUnderscoreNamingStrategyDefaults()
|
public function testUnderscoreNamingStrategyDefaults()
|
||||||
{
|
{
|
||||||
$namingStrategy = new \Doctrine\ORM\UnderscoreNamingStrategy(\Doctrine\ORM\UnderscoreNamingStrategy::CASE_UPPER);
|
$namingStrategy = new \Doctrine\ORM\UnderscoreNamingStrategy(CASE_UPPER);
|
||||||
$oneToOneMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy);
|
$oneToOneMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy);
|
||||||
$manyToManyMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy);
|
$manyToManyMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
*/
|
*/
|
||||||
static private function underscoreNamingLower()
|
static private function underscoreNamingLower()
|
||||||
{
|
{
|
||||||
return new UnderscoreNamingStrategy(UnderscoreNamingStrategy::CASE_LOWER);
|
return new UnderscoreNamingStrategy(CASE_LOWER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,7 +34,7 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
*/
|
*/
|
||||||
static private function underscoreNamingUpper()
|
static private function underscoreNamingUpper()
|
||||||
{
|
{
|
||||||
return new UnderscoreNamingStrategy(UnderscoreNamingStrategy::CASE_UPPER);
|
return new UnderscoreNamingStrategy(CASE_UPPER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,9 +118,9 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider dataPropertyToColumnName
|
* @dataProvider dataPropertyToColumnName
|
||||||
*
|
*
|
||||||
* @param NamingStrategy $strategy
|
* @param NamingStrategy $strategy
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
* @param string $propertyName
|
* @param string $propertyName
|
||||||
*/
|
*/
|
||||||
public function testPropertyToColumnName(NamingStrategy $strategy, $expected, $propertyName)
|
public function testPropertyToColumnName(NamingStrategy $strategy, $expected, $propertyName)
|
||||||
{
|
{
|
||||||
@ -147,10 +147,8 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider dataReferenceColumnName
|
* @dataProvider dataReferenceColumnName
|
||||||
*
|
*
|
||||||
* @param NamingStrategy $strategy
|
* @param NamingStrategy $strategy
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
* @param string $joinedColumn
|
|
||||||
* @param string $joinedTable
|
|
||||||
*/
|
*/
|
||||||
public function testReferenceColumnName(NamingStrategy $strategy, $expected)
|
public function testReferenceColumnName(NamingStrategy $strategy, $expected)
|
||||||
{
|
{
|
||||||
@ -186,9 +184,9 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider dataJoinColumnName
|
* @dataProvider dataJoinColumnName
|
||||||
*
|
*
|
||||||
* @param NamingStrategy $strategy
|
* @param NamingStrategy $strategy
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
* @param string $propertyName
|
* @param string $propertyName
|
||||||
*/
|
*/
|
||||||
public function testJoinColumnName(NamingStrategy $strategy, $expected, $propertyName)
|
public function testJoinColumnName(NamingStrategy $strategy, $expected, $propertyName)
|
||||||
{
|
{
|
||||||
@ -240,11 +238,11 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider dataJoinTableName
|
* @dataProvider dataJoinTableName
|
||||||
*
|
*
|
||||||
* @param NamingStrategy $strategy
|
* @param NamingStrategy $strategy
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
* @param string $ownerEntity
|
* @param string $ownerEntity
|
||||||
* @param string $associatedEntity
|
* @param string $associatedEntity
|
||||||
* @param string $propertyName
|
* @param string $propertyName
|
||||||
*/
|
*/
|
||||||
public function testJoinTableName(NamingStrategy $strategy, $expected, $ownerEntity, $associatedEntity, $propertyName = null)
|
public function testJoinTableName(NamingStrategy $strategy, $expected, $ownerEntity, $associatedEntity, $propertyName = null)
|
||||||
{
|
{
|
||||||
@ -287,11 +285,11 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider dataJoinKeyColumnName
|
* @dataProvider dataJoinKeyColumnName
|
||||||
*
|
*
|
||||||
* @param NamingStrategy $strategy
|
* @param NamingStrategy $strategy
|
||||||
* @param string $expected
|
* @param string $expected
|
||||||
* @param string $propertyEntityName
|
* @param string $propertyEntityName
|
||||||
* @param string $referencedColumnName
|
* @param string $referencedColumnName
|
||||||
* @param string $propertyName
|
* @param string $propertyName
|
||||||
*/
|
*/
|
||||||
public function testJoinKeyColumnName(NamingStrategy $strategy, $expected, $propertyEntityName, $referencedColumnName = null, $propertyName = null)
|
public function testJoinKeyColumnName(NamingStrategy $strategy, $expected, $propertyEntityName, $referencedColumnName = null, $propertyName = null)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user