Skip to content

Commit

Permalink
[2.0] Converted constant values from strings to integers.
Browse files Browse the repository at this point in the history
  • Loading branch information
romanb committed Jun 7, 2009
1 parent 9f42e2d commit 6e5a506
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 40 deletions.
19 changes: 14 additions & 5 deletions doctrine-mapping.xsd
Expand Up @@ -57,12 +57,21 @@
</xs:complexType>

<xs:simpleType name="inheritance-type">
<xs:restriction base="xs:string">
<xs:enumeration value="single-table"/>
<xs:enumeration value="joined"/>
<xs:enumeration value="table-per-class"/>
<xs:restriction base="xs:token">
<xs:enumeration value="SINGLE_TABLE"/>
<xs:enumeration value="JOINED"/>
<xs:enumeration value="TABLE_PER_CLASS"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="generator-strategy">
<xs:restriction base="xs:token">
<xs:enumeration value="TABLE"/>
<xs:enumeration value="SEQUENCE"/>
<xs:enumeration value="IDENTITY"/>
<xs:enumeration value="AUTO"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="field">
<xs:attribute name="name" type="xs:NMTOKEN" use="required" />
Expand All @@ -72,7 +81,7 @@
</xs:complexType>

<xs:complexType name="generator">
<xs:attribute name="strategy" type="xs:NMTOKEN" use="required" />
<xs:attribute name="strategy" type="orm:generator-strategy" use="required" />
</xs:complexType>

<xs:complexType name="id">
Expand Down
19 changes: 10 additions & 9 deletions lib/Doctrine/ORM/Mapping/ClassMetadata.php
Expand Up @@ -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
* <tt>Class Table Inheritance</tt>.
*/
const INHERITANCE_TYPE_JOINED = 'joined';
const INHERITANCE_TYPE_JOINED = 2;
/**
* SINGLE_TABLE means the class will be persisted according to the rules of
* <tt>Single Table Inheritance</tt>.
*/
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 <tt>Concrete Table Inheritance</tt>.
*/
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
Expand Down Expand Up @@ -1749,6 +1749,7 @@ public function setSequenceGeneratorDefinition(array $definition)
* Creates a string representation of this instance.
*
* @return string The string representation of this instance.
* @todo Construct meaningful string representation.
*/
public function __toString()
{
Expand Down
11 changes: 9 additions & 2 deletions lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Expand Up @@ -63,7 +63,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)

// 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
Expand Down Expand Up @@ -130,7 +130,14 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
$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);

Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
Expand Up @@ -86,7 +86,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
$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']));
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
Expand Up @@ -87,7 +87,8 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
$metadata->mapField($mapping);

if (isset($idElement['generator'])) {
$metadata->setIdGeneratorType($idElement['generator']['strategy']);
$metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_'
. $idElement['generator']['strategy']));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/CMS/CmsAddress.php
Expand Up @@ -14,7 +14,7 @@ class CmsAddress
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
public $id;

Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/CMS/CmsArticle.php
Expand Up @@ -11,7 +11,7 @@ class CmsArticle
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/CMS/CmsComment.php
Expand Up @@ -11,7 +11,7 @@ class CmsComment
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/CMS/CmsEmployee.php
Expand Up @@ -14,7 +14,7 @@ class CmsEmployee
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
private $id;

Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/CMS/CmsGroup.php
Expand Up @@ -18,7 +18,7 @@ class CmsGroup
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/CMS/CmsUser.php
Expand Up @@ -10,7 +10,7 @@ class CmsUser
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/Models/Company/CompanyPerson.php
Expand Up @@ -9,7 +9,7 @@
* @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"})
Expand All @@ -19,7 +19,7 @@ class CompanyPerson
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/Forum/ForumAvatar.php
Expand Up @@ -11,7 +11,7 @@ class ForumAvatar
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
}
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/Forum/ForumEntry.php
Expand Up @@ -11,7 +11,7 @@ class ForumEntry
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Models/Forum/ForumUser.php
Expand Up @@ -11,7 +11,7 @@ class ForumUser
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
Expand Down
Expand Up @@ -97,7 +97,7 @@ public function testCRUD()

/**
* @Entity
* @InheritanceType("singleTable")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @SubClasses({"Doctrine\Tests\ORM\Functional\ChildEntity"})
* @DiscriminatorValue("parent")
Expand All @@ -106,7 +106,7 @@ class ParentEntity {
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
private $id;

Expand Down Expand Up @@ -168,7 +168,7 @@ class RelatedEntity {
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php
Expand Up @@ -27,25 +27,25 @@ public function testGetMetadataForSingleClass()
// 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);
$cmf->setMetadataForClass('Doctrine\Tests\ORM\Mapping\TestEntity1', $cm1);

// 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);
}
}

Expand Down
Expand Up @@ -8,7 +8,7 @@
<entity name="XmlMappingTest\User" table="cms_users">

<id name="id" type="integer" column="id">
<generator strategy="auto"/>
<generator strategy="AUTO"/>
</id>

<field name="name" column="name" type="string" length="50"/>
Expand All @@ -34,7 +34,6 @@
</join-table>
</many-to-many>


</entity>

</doctrine-mapping>
Expand Up @@ -5,7 +5,7 @@ YamlMappingTest\User:
id:
type: integer
generator:
strategy: auto
strategy: AUTO
fields:
name:
type: string
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
Expand Up @@ -193,7 +193,7 @@ class NotifyChangedEntity implements \Doctrine\Common\NotifyPropertyChanged
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="auto")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
Expand Down

0 comments on commit 6e5a506

Please sign in to comment.