From 6e5a5068a6637938ba4c4183fdf60c45ba4162c6 Mon Sep 17 00:00:00 2001 From: romanb Date: Sun, 7 Jun 2009 17:20:37 +0000 Subject: [PATCH] [2.0] Converted constant values from strings to integers. --- doctrine-mapping.xsd | 19 ++++++++++++++----- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 19 ++++++++++--------- .../ORM/Mapping/Driver/AnnotationDriver.php | 11 +++++++++-- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 3 ++- .../ORM/Mapping/Driver/YamlDriver.php | 3 ++- .../Doctrine/Tests/Models/CMS/CmsAddress.php | 2 +- .../Doctrine/Tests/Models/CMS/CmsArticle.php | 2 +- .../Doctrine/Tests/Models/CMS/CmsComment.php | 2 +- .../Doctrine/Tests/Models/CMS/CmsEmployee.php | 2 +- tests/Doctrine/Tests/Models/CMS/CmsGroup.php | 2 +- tests/Doctrine/Tests/Models/CMS/CmsUser.php | 2 +- .../Tests/Models/Company/CompanyPerson.php | 4 ++-- .../Tests/Models/Forum/ForumAvatar.php | 2 +- .../Tests/Models/Forum/ForumEntry.php | 2 +- .../Doctrine/Tests/Models/Forum/ForumUser.php | 2 +- .../Functional/SingleTableInheritanceTest.php | 6 +++--- .../ORM/Mapping/ClassMetadataFactoryTest.php | 8 ++++---- .../Mapping/xml/XmlMappingTest.User.dcm.xml | 3 +-- .../Mapping/yaml/YamlMappingTest.User.dcm.yml | 2 +- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 2 +- 20 files changed, 58 insertions(+), 40 deletions(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index 97d15379b..25976c428 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -57,12 +57,21 @@ - - - - + + + + + + + + + + + + + @@ -72,7 +81,7 @@ - + diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 1c40bdb13..d56af872c 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -46,52 +46,52 @@ final class ClassMetadata * NONE means the class does not participate in an inheritance hierarchy * and therefore does not need an inheritance mapping type. */ - const INHERITANCE_TYPE_NONE = 'none'; + const INHERITANCE_TYPE_NONE = 1; /** * JOINED means the class will be persisted according to the rules of * Class Table Inheritance. */ - const INHERITANCE_TYPE_JOINED = 'joined'; + const INHERITANCE_TYPE_JOINED = 2; /** * SINGLE_TABLE means the class will be persisted according to the rules of * Single Table Inheritance. */ - const INHERITANCE_TYPE_SINGLE_TABLE = 'singleTable'; + const INHERITANCE_TYPE_SINGLE_TABLE = 3; /** * TABLE_PER_CLASS means the class will be persisted according to the rules * of Concrete Table Inheritance. */ - const INHERITANCE_TYPE_TABLE_PER_CLASS = 'tablePerClass'; + const INHERITANCE_TYPE_TABLE_PER_CLASS = 4; /* The Id generator types. */ /** * AUTO means the generator type will depend on what the used platform prefers. * Offers full portability. */ - const GENERATOR_TYPE_AUTO = 'auto'; + const GENERATOR_TYPE_AUTO = 1; /** * SEQUENCE means a separate sequence object will be used. Platforms that do * not have native sequence support may emulate it. Full portability is currently * not guaranteed. */ - const GENERATOR_TYPE_SEQUENCE = 'sequence'; + const GENERATOR_TYPE_SEQUENCE = 2; /** * TABLE means a separate table is used for id generation. * Offers full portability. */ - const GENERATOR_TYPE_TABLE = 'table'; + const GENERATOR_TYPE_TABLE = 3; /** * IDENTITY means an identity column is used for id generation. The database * will fill in the id column on insertion. Platforms that do not support * native identity columns may emulate them. Full portability is currently * not guaranteed. */ - const GENERATOR_TYPE_IDENTITY = 'identity'; + const GENERATOR_TYPE_IDENTITY = 4; /** * NONE means the class does not have a generated id. That means the class * must have a natural id. */ - const GENERATOR_TYPE_NONE = 'none'; + const GENERATOR_TYPE_NONE = 5; /** * DEFERRED_IMPLICIT means that changes of entities are calculated at commit-time * by doing a property-by-property comparison with the original data. This will @@ -1749,6 +1749,7 @@ final class ClassMetadata * Creates a string representation of this instance. * * @return string The string representation of this instance. + * @todo Construct meaningful string representation. */ public function __toString() { diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 82f2f0609..f183a91ba 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -63,7 +63,7 @@ class AnnotationDriver implements Driver // Evaluate InheritanceType annotation if ($inheritanceTypeAnnot = $annotClass->getAnnotation('InheritanceType')) { - $metadata->setInheritanceType($inheritanceTypeAnnot->value); + $metadata->setInheritanceType(constant('\Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value)); } // Evaluate DiscriminatorColumn annotation @@ -130,7 +130,14 @@ class AnnotationDriver implements Driver $mapping['id'] = true; } if ($generatedValueAnnot = $property->getAnnotation('GeneratedValue')) { - $metadata->setIdGeneratorType($generatedValueAnnot->strategy); + if ($generatedValueAnnot->strategy == 'auto') { + try { + throw new \Exception(); + } catch (\Exception $e) { + var_dump($e->getTraceAsString()); + } + } + $metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' . $generatedValueAnnot->strategy)); } $metadata->mapField($mapping); diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 8098f1c7f..257eff2eb 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -86,7 +86,8 @@ class XmlDriver extends AbstractFileDriver $metadata->mapField($mapping); if (isset($idElement->generator)) { - $metadata->setIdGeneratorType((string)$idElement->generator['strategy']); + $metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' + . (string)$idElement->generator['strategy'])); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 77bb3259f..01e882bf9 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -87,7 +87,8 @@ class YamlDriver extends AbstractFileDriver $metadata->mapField($mapping); if (isset($idElement['generator'])) { - $metadata->setIdGeneratorType($idElement['generator']['strategy']); + $metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' + . $idElement['generator']['strategy'])); } } diff --git a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php index d5980cffc..181e28b22 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php @@ -14,7 +14,7 @@ class CmsAddress /** * @Column(type="integer") * @Id - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ public $id; diff --git a/tests/Doctrine/Tests/Models/CMS/CmsArticle.php b/tests/Doctrine/Tests/Models/CMS/CmsArticle.php index 2ff8a66f9..719f4b3d9 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsArticle.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsArticle.php @@ -11,7 +11,7 @@ class CmsArticle /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ public $id; /** diff --git a/tests/Doctrine/Tests/Models/CMS/CmsComment.php b/tests/Doctrine/Tests/Models/CMS/CmsComment.php index 8e327a9a8..c1991474f 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsComment.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsComment.php @@ -11,7 +11,7 @@ class CmsComment /** * @Column(type="integer") * @Id - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ public $id; /** diff --git a/tests/Doctrine/Tests/Models/CMS/CmsEmployee.php b/tests/Doctrine/Tests/Models/CMS/CmsEmployee.php index 8ecb26420..9acdbc6f4 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsEmployee.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsEmployee.php @@ -14,7 +14,7 @@ class CmsEmployee /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ private $id; diff --git a/tests/Doctrine/Tests/Models/CMS/CmsGroup.php b/tests/Doctrine/Tests/Models/CMS/CmsGroup.php index 2a4908927..3bdfcba1f 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsGroup.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsGroup.php @@ -18,7 +18,7 @@ class CmsGroup /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ public $id; /** diff --git a/tests/Doctrine/Tests/Models/CMS/CmsUser.php b/tests/Doctrine/Tests/Models/CMS/CmsUser.php index d8760cac0..50ab5daee 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsUser.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsUser.php @@ -10,7 +10,7 @@ class CmsUser { /** * @Id @Column(type="integer") - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ public $id; /** diff --git a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php index 03180d8ca..9444352ad 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php @@ -9,7 +9,7 @@ namespace Doctrine\Tests\Models\Company; * @Entity * @Table(name="company_persons") * @DiscriminatorValue("person") - * @InheritanceType("joined") + * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="string") * @SubClasses({"Doctrine\Tests\Models\Company\CompanyEmployee", "Doctrine\Tests\Models\Company\CompanyManager"}) @@ -19,7 +19,7 @@ class CompanyPerson /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ private $id; /** diff --git a/tests/Doctrine/Tests/Models/Forum/ForumAvatar.php b/tests/Doctrine/Tests/Models/Forum/ForumAvatar.php index 691ac022d..ce4e3c30d 100644 --- a/tests/Doctrine/Tests/Models/Forum/ForumAvatar.php +++ b/tests/Doctrine/Tests/Models/Forum/ForumAvatar.php @@ -11,7 +11,7 @@ class ForumAvatar /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ public $id; } diff --git a/tests/Doctrine/Tests/Models/Forum/ForumEntry.php b/tests/Doctrine/Tests/Models/Forum/ForumEntry.php index 3a114115e..736c2adb6 100644 --- a/tests/Doctrine/Tests/Models/Forum/ForumEntry.php +++ b/tests/Doctrine/Tests/Models/Forum/ForumEntry.php @@ -11,7 +11,7 @@ class ForumEntry /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ public $id; /** diff --git a/tests/Doctrine/Tests/Models/Forum/ForumUser.php b/tests/Doctrine/Tests/Models/Forum/ForumUser.php index ad2977c0e..6b15890ec 100644 --- a/tests/Doctrine/Tests/Models/Forum/ForumUser.php +++ b/tests/Doctrine/Tests/Models/Forum/ForumUser.php @@ -11,7 +11,7 @@ class ForumUser /** * @Column(type="integer") * @Id - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ public $id; /** diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php index 0b5016cb1..9ee31b085 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php @@ -97,7 +97,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase /** * @Entity - * @InheritanceType("singleTable") + * @InheritanceType("SINGLE_TABLE") * @DiscriminatorColumn(name="discr", type="string") * @SubClasses({"Doctrine\Tests\ORM\Functional\ChildEntity"}) * @DiscriminatorValue("parent") @@ -106,7 +106,7 @@ class ParentEntity { /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ private $id; @@ -168,7 +168,7 @@ class RelatedEntity { /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ private $id; /** diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index cbebad0a3..5f50d80fc 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -27,7 +27,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase // and a mapped association $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this')); // and an id generator type - $cm1->setIdGeneratorType('auto'); + $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO); // SUT $cmf = new ClassMetadataFactoryTestSubject($mockDriver, $mockPlatform); @@ -35,17 +35,17 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase // Prechecks $this->assertEquals(array(), $cm1->parentClasses); - $this->assertEquals('none', $cm1->inheritanceType); + $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm1->inheritanceType); $this->assertTrue($cm1->hasField('name')); $this->assertEquals(1, count($cm1->associationMappings)); - $this->assertEquals('auto', $cm1->generatorType); + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType); // Go $cm1 = $cmf->getMetadataFor('Doctrine\Tests\ORM\Mapping\TestEntity1'); $this->assertEquals(array(), $cm1->parentClasses); $this->assertTrue($cm1->hasField('name')); - $this->assertEquals('sequence', $cm1->generatorType); + $this->assertEquals(ClassMetadata::GENERATOR_TYPE_SEQUENCE, $cm1->generatorType); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/XmlMappingTest.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/XmlMappingTest.User.dcm.xml index 57abf84ea..0945821a5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/XmlMappingTest.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/XmlMappingTest.User.dcm.xml @@ -8,7 +8,7 @@ - + @@ -34,7 +34,6 @@ - \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/YamlMappingTest.User.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/YamlMappingTest.User.dcm.yml index d6c63d417..6de3a2f92 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/YamlMappingTest.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/YamlMappingTest.User.dcm.yml @@ -5,7 +5,7 @@ YamlMappingTest\User: id: type: integer generator: - strategy: auto + strategy: AUTO fields: name: type: string diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 89a128922..dff775bf3 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -193,7 +193,7 @@ class NotifyChangedEntity implements \Doctrine\Common\NotifyPropertyChanged /** * @Id * @Column(type="integer") - * @GeneratedValue(strategy="auto") + * @GeneratedValue(strategy="AUTO") */ private $id; /**