Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
fd89892c
Commit
fd89892c
authored
Aug 24, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Updating YAML and XML drivers to be synchronized with Annotations driver.
parent
27356225
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
423 additions
and
324 deletions
+423
-324
doctrine-mapping.xsd
doctrine-mapping.xsd
+5
-5
AnnotationDriver.php
lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
+0
-6
XmlDriver.php
lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
+209
-154
YamlDriver.php
lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
+190
-154
MappingDriverTest.php
tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php
+12
-0
Doctrine.Tests.ORM.Mapping.User.dcm.xml
...s/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml
+3
-4
Doctrine.Tests.ORM.Mapping.User.dcm.yml
.../ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml
+4
-1
No files found.
doctrine-mapping.xsd
View file @
fd89892c
...
...
@@ -33,7 +33,7 @@
</xs:sequence>
</xs:complexType>
<xs:simpleType
name=
"lifecycle-
callback
-type"
>
<xs:simpleType
name=
"lifecycle-
listener
-type"
>
<xs:restriction
base=
"xs:token"
>
<xs:enumeration
value=
"prePersist"
/>
<xs:enumeration
value=
"postPersist"
/>
...
...
@@ -45,14 +45,14 @@
</xs:restriction>
</xs:simpleType>
<xs:complexType
name=
"lifecycle-
callback
"
>
<xs:attribute
name=
"type"
type=
"orm:lifecycle-
callback
-type"
use=
"required"
/>
<xs:complexType
name=
"lifecycle-
listener
"
>
<xs:attribute
name=
"type"
type=
"orm:lifecycle-
listener
-type"
use=
"required"
/>
<xs:attribute
name=
"method"
type=
"xs:NMTOKEN"
use=
"required"
/>
</xs:complexType>
<xs:complexType
name=
"lifecycle-
callbacks
"
>
<xs:complexType
name=
"lifecycle-
listener
"
>
<xs:sequence>
<xs:element
name=
"lifecycle-
callback"
type=
"orm:lifecycle-callback
"
minOccurs=
"1"
maxOccurs=
"unbounded"
/>
<xs:element
name=
"lifecycle-
listener"
type=
"orm:lifecycle-listener
"
minOccurs=
"1"
maxOccurs=
"unbounded"
/>
</xs:sequence>
</xs:complexType>
...
...
lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
View file @
fd89892c
...
...
@@ -112,12 +112,6 @@ class AnnotationDriver implements Driver
$metadata
->
setDiscriminatorMap
(
$discrMapAnnot
->
value
);
}
// Evaluate DoctrineSubClasses annotation
if
(
isset
(
$classAnnotations
[
'Doctrine\ORM\Mapping\SubClasses'
]))
{
$subClassesAnnot
=
$classAnnotations
[
'Doctrine\ORM\Mapping\SubClasses'
];
$metadata
->
setSubclasses
(
$subClassesAnnot
->
value
);
}
// Evaluate DoctrineChangeTrackingPolicy annotation
if
(
isset
(
$classAnnotations
[
'Doctrine\ORM\Mapping\ChangeTrackingPolicy'
]))
{
$changeTrackingAnnot
=
$classAnnotations
[
'Doctrine\ORM\Mapping\ChangeTrackingPolicy'
];
...
...
lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
View file @
fd89892c
...
...
@@ -41,9 +41,19 @@ class XmlDriver extends AbstractFileDriver
*/
public
function
loadMetadataForClass
(
$className
,
ClassMetadata
$metadata
)
{
$class
=
$metadata
->
getReflectionClass
();
$xmlRoot
=
$this
->
getElement
(
$className
);
if
(
$xmlRoot
->
getName
()
==
'entity'
)
{
$metadata
->
setCustomRepositoryClass
(
isset
(
$xmlRoot
[
'repository-class'
])
?
$xmlRoot
[
'repository-class'
]
:
null
);
}
else
if
(
$xmlRoot
->
getName
()
==
'mapped-superclass'
)
{
$metadata
->
isMappedSuperclass
=
true
;
}
else
{
throw
DoctrineException
::
updateMe
(
"
$className
is no entity or mapped superclass."
);
}
// Evaluate <entity...> attributes
if
(
isset
(
$xmlRoot
[
'table'
]))
{
...
...
@@ -56,6 +66,26 @@ class XmlDriver extends AbstractFileDriver
$metadata
->
setInheritanceType
((
string
)
$xmlRoot
[
'inheritance-type'
]);
}
// Evaluate <discriminator-column...>
if
(
isset
(
$xmlRoot
->
{
'discriminator-column'
}))
{
$discrColumn
=
$xmlRoot
->
{
'discriminator-column'
};
$metadata
->
setDiscriminatorColumn
(
array
(
'name'
=>
(
string
)
$discrColumn
->
name
,
'type'
=>
(
string
)
$discrColumn
->
type
,
'length'
=>
(
string
)
$discrColumn
->
length
));
}
// Evaluate <discriminator-map...>
if
(
isset
(
$xmlRoot
->
{
'discriminator-map'
}))
{
$metadata
->
setDiscriminatorMap
((
array
)
$xmlRoot
->
{
'discriminator-map'
});
}
// Evaluate <change-tracking-policy...>
if
(
isset
(
$xmlRoot
->
{
'change-tracking-policy'
}))
{
$metadata
->
setChangeTrackingPolicy
((
array
)
$xmlRoot
->
{
'change-tracking-policy'
});
}
// Evaluate <indexes...>
if
(
isset
(
$xmlRoot
->
indexes
))
{
foreach
(
$xmlRoot
->
indexes
->
index
as
$index
)
{
...
...
@@ -113,6 +143,18 @@ class XmlDriver extends AbstractFileDriver
$metadata
->
setIdGeneratorType
(
constant
(
'Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_'
.
(
string
)
$idElement
->
generator
[
'strategy'
]));
}
// Check for SequenceGenerator/TableGenerator definition
if
(
isset
(
$idElement
->
{
'sequence-generator'
}))
{
$seqGenerator
=
$idElement
->
{
'sequence-generator'
};
$metadata
->
setSequenceGeneratorDefinition
(
array
(
'sequenceName'
=>
$seqGenerator
->
{
'sequence-name'
},
'allocationSize'
=>
$seqGenerator
->
{
'allocation-size'
},
'initialValue'
=>
$seqGeneratorAnnot
->
{
'initial-value'
}
));
}
else
if
(
isset
(
$idElement
->
{
'table-generator'
}))
{
throw
DoctrineException
::
tableIdGeneratorNotImplemented
();
}
}
// Evaluate <one-to-one ...> mappings
...
...
@@ -120,7 +162,7 @@ class XmlDriver extends AbstractFileDriver
foreach
(
$xmlRoot
->
{
'one-to-one'
}
as
$oneToOneElement
)
{
$mapping
=
array
(
'fieldName'
=>
(
string
)
$oneToOneElement
[
'field'
],
'targetEntity'
=>
(
string
)
$oneToOneElement
[
'target-entity'
]
'targetEntity'
=>
(
string
)
$oneToOneElement
[
'target-entity'
],
);
if
(
isset
(
$oneToOneElement
[
'mapped-by'
]))
{
$mapping
[
'mappedBy'
]
=
(
string
)
$oneToOneElement
[
'mapped-by'
];
...
...
@@ -137,11 +179,12 @@ class XmlDriver extends AbstractFileDriver
}
$mapping
[
'joinColumns'
]
=
$joinColumns
;
}
if
(
isset
(
$oneToOneElement
->
cascade
))
{
$mapping
[
'cascade'
]
=
$this
->
_getCascadeMappings
(
$oneToOneElement
->
cascade
);
}
if
(
isset
(
$oneToOneElement
->
{
'orphan-removal'
}))
{
$mapping
[
'orphanRemoval'
]
=
(
bool
)
$oneToOneElement
->
{
'orphan-removal'
};
}
$metadata
->
mapOneToOne
(
$mapping
);
}
}
...
...
@@ -157,6 +200,9 @@ class XmlDriver extends AbstractFileDriver
if
(
isset
(
$oneToManyElement
->
cascade
))
{
$mapping
[
'cascade'
]
=
$this
->
_getCascadeMappings
(
$oneToManyElement
->
cascade
);
}
if
(
isset
(
$oneToManyElement
->
{
'orphan-removal'
}))
{
$mapping
[
'orphanRemoval'
]
=
(
bool
)
$oneToManyElement
->
{
'orphan-removal'
};
}
$metadata
->
mapOneToMany
(
$mapping
);
}
}
...
...
@@ -185,6 +231,9 @@ class XmlDriver extends AbstractFileDriver
if
(
isset
(
$manyToOneElement
->
cascade
))
{
$mapping
[
'cascade'
]
=
$this
->
_getCascadeMappings
(
$manyToOneElement
->
cascade
);
}
if
(
isset
(
$manyToOneElement
->
{
'orphan-removal'
}))
{
$mapping
[
'orphanRemoval'
]
=
(
bool
)
$manyToOneElement
->
{
'orphan-removal'
};
}
$metadata
->
mapManyToOne
(
$mapping
);
}
}
...
...
@@ -196,7 +245,6 @@ class XmlDriver extends AbstractFileDriver
'fieldName'
=>
(
string
)
$manyToManyElement
[
'field'
],
'targetEntity'
=>
(
string
)
$manyToManyElement
[
'target-entity'
]
);
if
(
isset
(
$manyToManyElement
[
'mappedBy'
]))
{
$mapping
[
'mappedBy'
]
=
(
string
)
$manyToManyElement
[
'mapped-by'
];
}
else
if
(
isset
(
$manyToManyElement
->
{
'join-table'
}))
{
...
...
@@ -217,17 +265,24 @@ class XmlDriver extends AbstractFileDriver
}
else
{
throw
MappingException
::
invalidMapping
(
$mapping
[
'fieldName'
]);
}
if
(
isset
(
$manyToManyElement
->
cascade
))
{
$mapping
[
'cascade'
]
=
$this
->
_getCascadeMappings
(
$manyToManyElement
->
cascade
);
}
if
(
isset
(
$manyToManyElement
->
{
'orphan-removal'
}))
{
$mapping
[
'orphanRemoval'
]
=
(
bool
)
$manyToManyElement
->
{
'orphan-removal'
};
}
$metadata
->
mapManyToMany
(
$mapping
);
}
}
}
else
if
(
$xmlRoot
->
getName
()
==
'mapped-superclass'
)
{
throw
MappingException
::
notImplemented
(
'Mapped superclasses are not yet supported.'
);
// Evaluate <lifecycle-listener...>
if
(
isset
(
$xmlRoot
->
{
'lifecycle-listener'
}))
{
foreach
(
$xmlRoot
->
{
'lifecycle-listener'
}
as
$lifecycleListener
)
{
$method
=
$class
->
getMethod
((
string
)
$lifecycleListener
[
'method'
]);
if
(
$method
->
isPublic
())
{
$metadata
->
addLifecycleCallback
(
$method
->
getName
(),
constant
(
'\Doctrine\ORM\Events::'
.
(
string
)
$lifecycleListener
[
'type'
]));
}
}
}
}
...
...
lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
View file @
fd89892c
...
...
@@ -42,9 +42,19 @@ class YamlDriver extends AbstractFileDriver
public
function
loadMetadataForClass
(
$className
,
ClassMetadata
$metadata
)
{
$class
=
$metadata
->
getReflectionClass
();
$element
=
$this
->
getElement
(
$className
);
if
(
$element
[
'type'
]
==
'entity'
)
{
$metadata
->
setCustomRepositoryClass
(
isset
(
$element
[
'repositoryClass'
])
?
$xmlRoot
[
'repositoryClass'
]
:
null
);
}
else
if
(
$element
[
'type'
]
==
'mappedSuperclass'
)
{
$metadata
->
isMappedSuperclass
=
true
;
}
else
{
throw
DoctrineException
::
updateMe
(
"
$className
is no entity or mapped superclass."
);
}
// Evaluate root level properties
if
(
isset
(
$element
[
'table'
]))
{
...
...
@@ -57,6 +67,26 @@ class YamlDriver extends AbstractFileDriver
$metadata
->
setInheritanceType
(
$element
[
'inheritanceType'
]);
}
// Evaluate discriminatorColumn
if
(
isset
(
$element
[
'discriminatorColumn'
]))
{
$discrColumn
=
$element
[
'discriminatorColumn'
];
$metadata
->
setDiscriminatorColumn
(
array
(
'name'
=>
$discrColumn
[
'name'
],
'type'
=>
$discrColumn
[
'type'
],
'length'
=>
$discrColumn
[
'length'
]
));
}
// Evaluate discriminatorMap
if
(
isset
(
$element
[
'discriminatorMap'
]))
{
$metadata
->
setDiscriminatorMap
(
$element
[
'discriminatorMap'
]);
}
// Evaluate changeTrackingPolicy
if
(
isset
(
$element
[
'changeTrackingPolicy'
]))
{
$metadata
->
setChangeTrackingPolicy
(
$element
[
'changeTrackingPolicy'
]);
}
// Evaluate indexes
if
(
isset
(
$element
[
'indexes'
]))
{
foreach
(
$element
[
'indexes'
]
as
$index
)
{
...
...
@@ -236,8 +266,14 @@ class YamlDriver extends AbstractFileDriver
}
}
}
else
if
(
$element
[
'type'
]
==
'mapped-superclass'
)
{
throw
MappingException
::
notImplemented
(
'Mapped superclasses are not yet supported.'
);
// Evaluate lifeCycleListener
if
(
isset
(
$element
[
'lifecycleListeners'
]))
{
foreach
(
$element
[
'lifecycleListeners'
]
as
$method
=>
$type
)
{
$method
=
$class
->
getMethod
(
$method
);
if
(
$method
->
isPublic
())
{
$metadata
->
addLifecycleCallback
(
$method
->
getName
(),
constant
(
'\Doctrine\ORM\Events::'
.
$type
));
}
}
}
}
...
...
tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php
View file @
fd89892c
...
...
@@ -97,6 +97,9 @@ class MappingDriverTest extends \Doctrine\Tests\OrmTestCase
$this
->
assertTrue
(
$class
->
associationMappings
[
'groups'
]
instanceof
\Doctrine\ORM\Mapping\ManyToManyMapping
);
$this
->
assertTrue
(
isset
(
$class
->
associationMappings
[
'groups'
]));
$this
->
assertTrue
(
$class
->
associationMappings
[
'groups'
]
->
isOwningSide
);
$this
->
assertEquals
(
count
(
$class
->
lifecycleCallbacks
),
2
);
$this
->
assertEquals
(
$class
->
lifecycleCallbacks
[
'prePersist'
][
0
],
'doStuffOnPrePersist'
);
$this
->
assertEquals
(
$class
->
lifecycleCallbacks
[
'postPersist'
][
0
],
'doStuffOnPostPersist'
);
}
}
...
...
@@ -108,4 +111,13 @@ class User {
private
$groups
;
// ... rest of code omitted, irrelevant for the mapping tests
public
function
doStuffOnPrePersist
()
{
}
public
function
doStuffOnPostPersist
()
{
}
}
\ No newline at end of file
tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml
View file @
fd89892c
...
...
@@ -7,9 +7,8 @@
<entity
name=
"Doctrine\Tests\ORM\Mapping\User"
table=
"cms_users"
>
<lifecycle-callbacks>
<lifecycle-callback
type=
"prePersist"
method=
"onPrePersist"
/>
</lifecycle-callbacks>
<lifecycle-listener
method=
"doStuffOnPrePersist"
type=
"prePersist"
/>
<lifecycle-listener
method=
"doStuffOnPostPersist"
type=
"postPersist"
/>
<id
name=
"id"
type=
"integer"
column=
"id"
>
<generator
strategy=
"AUTO"
/>
...
...
tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml
View file @
fd89892c
...
...
@@ -32,3 +32,6 @@ Doctrine\Tests\ORM\Mapping\User:
inverseJoinColumns
:
group_id
:
referencedColumnName
:
id
lifecycleListeners
:
doStuffOnPrePersist
:
prePersist
doStuffOnPostPersist
:
postPersist
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment