Skip to content

Commit

Permalink
Consistently use kebab-case in XML mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Jul 27, 2018
1 parent 1b40f78 commit 9ece373
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
14 changes: 7 additions & 7 deletions doctrine-mongo-mapping.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</xs:sequence>
<xs:attribute name="db" type="xs:NMTOKEN" />
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="writeConcern" type="xs:string" />
<xs:attribute name="write-concern" type="xs:string" />
<xs:attribute name="collection" type="xs:NMTOKEN" />
<xs:attribute name="capped-collection" type="xs:boolean" />
<xs:attribute name="capped-collection-size" type="xs:integer" />
Expand All @@ -76,7 +76,7 @@
<xs:attribute name="name" type="xs:NMTOKEN" />
<xs:attribute name="type" type="xs:NMTOKEN" />
<xs:attribute name="strategy" type="xs:NMTOKEN" default="set" />
<xs:attribute name="fieldName" type="xs:NMTOKEN" />
<xs:attribute name="field-name" type="xs:NMTOKEN" />
<xs:attribute name="embed" type="xs:boolean" />
<xs:attribute name="reference" type="xs:boolean" />
<xs:attribute name="version" type="xs:boolean" />
Expand All @@ -100,7 +100,7 @@
</xs:sequence>
<xs:attribute name="type" type="xs:NMTOKEN" />
<xs:attribute name="strategy" type="xs:NMTOKEN" default="auto" />
<xs:attribute name="fieldName" type="xs:NMTOKEN" default="id" />
<xs:attribute name="field-name" type="xs:NMTOKEN" default="id" />
</xs:complexType>

<xs:complexType name="id-generator-option">
Expand All @@ -116,7 +116,7 @@
</xs:sequence>
<xs:attribute name="target-document" type="xs:string" />
<xs:attribute name="field" type="xs:NMTOKEN" use="required" />
<xs:attribute name="fieldName" type="xs:NMTOKEN" />
<xs:attribute name="field-name" type="xs:NMTOKEN" />
<xs:attribute name="not-saved" type="xs:boolean" />
<xs:attribute name="nullable" type="xs:boolean" />
<xs:attribute name="also-load" type="xs:NMTOKEN" />
Expand All @@ -131,7 +131,7 @@
<xs:attribute name="target-document" type="xs:string" />
<xs:attribute name="collection-class" type="xs:string" />
<xs:attribute name="field" type="xs:NMTOKEN" use="required" />
<xs:attribute name="fieldName" type="xs:NMTOKEN" />
<xs:attribute name="field-name" type="xs:NMTOKEN" />
<xs:attribute name="strategy" type="xs:NMTOKEN" default="pushAll" />
<xs:attribute name="not-saved" type="xs:boolean" />
<xs:attribute name="nullable" type="xs:boolean" />
Expand All @@ -158,7 +158,7 @@
</xs:sequence>
<xs:attribute name="target-document" type="xs:string" />
<xs:attribute name="field" type="xs:NMTOKEN" use="required" />
<xs:attribute name="fieldName" type="xs:NMTOKEN" />
<xs:attribute name="field-name" type="xs:NMTOKEN" />
<xs:attribute name="simple" type="xs:boolean" /><!-- deprecated -->
<xs:attribute name="store-as" type="odm:reference-store-as" default="dbRefWithDb" />
<xs:attribute name="inversed-by" type="xs:NMTOKEN" />
Expand All @@ -183,7 +183,7 @@
<xs:attribute name="target-document" type="xs:string" />
<xs:attribute name="collection-class" type="xs:string" />
<xs:attribute name="field" type="xs:NMTOKEN" use="required" />
<xs:attribute name="fieldName" type="xs:NMTOKEN" />
<xs:attribute name="field-name" type="xs:NMTOKEN" />
<xs:attribute name="simple" type="xs:boolean" /><!-- deprecated -->
<xs:attribute name="store-as" type="odm:reference-store-as" default="dbRefWithDb" />
<xs:attribute name="strategy" type="xs:NMTOKEN" default="pushAll" />
Expand Down
23 changes: 11 additions & 12 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Ma
$class->setCollection((string) $xmlRoot['collection']);
}
}
if (isset($xmlRoot['writeConcern'])) {
$class->setWriteConcern((string) $xmlRoot['writeConcern']);
if (isset($xmlRoot['write-concern'])) {
$class->setWriteConcern((string) $xmlRoot['write-concern']);
}
if (isset($xmlRoot['inheritance-type'])) {
$inheritanceType = (string) $xmlRoot['inheritance-type'];
Expand All @@ -93,12 +93,7 @@ public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Ma
}
if (isset($xmlRoot->{'discriminator-field'})) {
$discrField = $xmlRoot->{'discriminator-field'};
/* XSD only allows for "name", which is consistent with association
* configurations, but fall back to "fieldName" for BC.
*/
$class->setDiscriminatorField(
(string) ($discrField['name'] ?? $discrField['fieldName'])
);
$class->setDiscriminatorField((string) $discrField['name']);
}
if (isset($xmlRoot->{'discriminator-map'})) {
$map = [];
Expand Down Expand Up @@ -172,6 +167,10 @@ public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Ma
$mapping['notSaved'] = ((string) $attributes['not-saved'] === 'true');
}

if (isset($attributes['field-name'])) {
$mapping['fieldName'] = (string) $attributes['field-name'];
}

if (isset($attributes['also-load'])) {
$mapping['alsoLoadFields'] = explode(',', $attributes['also-load']);
} elseif (isset($attributes['version'])) {
Expand Down Expand Up @@ -268,8 +267,8 @@ private function addEmbedMapping(ClassMetadata $class, $embed, $type)
'name' => (string) $attributes['field'],
'strategy' => (string) ($attributes['strategy'] ?? $defaultStrategy),
];
if (isset($attributes['fieldName'])) {
$mapping['fieldName'] = (string) $attributes['fieldName'];
if (isset($attributes['field-name'])) {
$mapping['fieldName'] = (string) $attributes['field-name'];
}
if (isset($embed->{'discriminator-field'})) {
$attr = $embed->{'discriminator-field'};
Expand Down Expand Up @@ -319,8 +318,8 @@ private function addReferenceMapping(ClassMetadata $class, $reference, $type)
'prime' => [],
];

if (isset($attributes['fieldName'])) {
$mapping['fieldName'] = (string) $attributes['fieldName'];
if (isset($attributes['field-name'])) {
$mapping['fieldName'] = (string) $attributes['field-name'];
}
if (isset($reference->{'discriminator-field'})) {
$attr = $reference->{'discriminator-field'};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">

<document name="Doctrine\ODM\MongoDB\Tests\Mapping\AbstractMappingDriverUser" collection="cms_users" writeConcern="1" read-only="true">
<document name="Doctrine\ODM\MongoDB\Tests\Mapping\AbstractMappingDriverUser" collection="cms_users" write-concern="1" read-only="true">
<discriminator-field name="discr" />
<discriminator-map>
<discriminator-mapping value="default" class="Doctrine\ODM\MongoDB\Tests\Mapping\AbstractMappingDriverUser" />
Expand All @@ -20,14 +20,14 @@
</tag-set>
<tag-set />
</read-preference>
<id fieldName="id" />
<field fieldName="version" version="true" type="int" />
<field fieldName="lock" lock="true" type="int" />
<field fieldName="name" name="username" type="string" />
<field fieldName="email" type="string" unique="true" drop-dups="true" order="desc" />
<field fieldName="mysqlProfileId" type="integer" unique="true" drop-dups="true" order="desc" />
<field fieldName="createdAt" type="date" />
<field fieldName="roles" type="collection" />
<id field-name="id" />
<field field-name="version" version="true" type="int" />
<field field-name="lock" lock="true" type="int" />
<field field-name="name" name="username" type="string" />
<field field-name="email" type="string" unique="true" drop-dups="true" order="desc" />
<field field-name="mysqlProfileId" type="integer" unique="true" drop-dups="true" order="desc" />
<field field-name="createdAt" type="date" />
<field field-name="roles" type="collection" />
<indexes>
<index unique="true">
<key name="username" order="desc" />
Expand Down Expand Up @@ -66,9 +66,9 @@
<all />
</cascade>
</reference-many>
<reference-many target-document="Phonenumber" fieldName="morePhoneNumbers" field="more_phone_numbers">
<reference-many target-document="Phonenumber" field-name="morePhoneNumbers" field="more_phone_numbers">
</reference-many>
<embed-one target-document="Phonenumber" fieldName="embeddedPhonenumber" field="embedded_phone_number">
<embed-one target-document="Phonenumber" field-name="embeddedPhonenumber" field="embedded_phone_number">
</embed-one>
<embed-many target-document="Phonenumber" collection-class="PhonenumberCollection" field="otherPhonenumbers">
<discriminator-field name="discr" />
Expand Down

0 comments on commit 9ece373

Please sign in to comment.