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
d90e71d0
Commit
d90e71d0
authored
Jun 01, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] First implementation of XmlDriver + tests. First draft of XSD document.
parent
de7dfb4f
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
696 additions
and
7 deletions
+696
-7
doctrine-mapping.xsd
doctrine-mapping.xsd
+143
-0
ClassLoader.php
lib/Doctrine/Common/ClassLoader.php
+1
-1
ClassMetadataFactory.php
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
+0
-2
AnnotationDriver.php
lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
+3
-3
XmlDriver.php
lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
+427
-0
OneToOneMapping.php
lib/Doctrine/ORM/Mapping/OneToOneMapping.php
+1
-1
AllTests.php
tests/Doctrine/Tests/ORM/Mapping/AllTests.php
+1
-0
XmlDriverTest.php
tests/Doctrine/Tests/ORM/Mapping/XmlDriverTest.php
+67
-0
User.php
tests/Doctrine/Tests/ORM/Mapping/xml/User.php
+13
-0
XmlMappingTest.User.dcm.xml
...octrine/Tests/ORM/Mapping/xml/XmlMappingTest.User.dcm.xml
+40
-0
No files found.
doctrine-mapping.xsd
0 → 100644
View file @
d90e71d0
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs=
"http://www.w3.org/2001/XMLSchema"
targetNamespace=
"http://schemas.doctrine-project.org/orm/doctrine-mapping"
xmlns:orm=
"http://schemas.doctrine-project.org/orm/doctrine-mapping"
elementFormDefault=
"qualified"
>
<xs:annotation>
<xs:documentation>
<![CDATA[
This is the XML Schema for the object/relational
mapping file used by Doctrine.
]]>
</xs:documentation>
</xs:annotation>
<xs:element
name=
"doctrine-mapping"
>
<xs:complexType>
<xs:sequence>
<xs:element
name=
"entity"
type=
"orm:entity"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType
name=
"emptyType"
/>
<xs:complexType
name=
"cascade-type"
>
<xs:sequence>
<xs:element
name=
"cascade-all"
type=
"orm:emptyType"
minOccurs=
"0"
/>
<xs:element
name=
"cascade-save"
type=
"orm:emptyType"
minOccurs=
"0"
/>
<xs:element
name=
"cascade-merge"
type=
"orm:emptyType"
minOccurs=
"0"
/>
<xs:element
name=
"cascade-delete"
type=
"orm:emptyType"
minOccurs=
"0"
/>
<xs:element
name=
"cascade-refresh"
type=
"orm:emptyType"
minOccurs=
"0"
/>
</xs:sequence>
</xs:complexType>
<xs:complexType
name=
"entity"
>
<xs:sequence>
<xs:element
name=
"id"
type=
"orm:id"
/>
<xs:element
name=
"field"
type=
"orm:field"
minOccurs=
"0"
/>
<xs:element
name=
"one-to-one"
type=
"orm:one-to-one"
minOccurs=
"0"
/>
<xs:element
name=
"one-to-many"
type=
"orm:one-to-many"
minOccurs=
"0"
/>
<xs:element
name=
"many-to-many"
type=
"orm:many-to-many"
minOccurs=
"0"
/>
</xs:sequence>
<xs:attribute
name=
"name"
type=
"xs:string"
use=
"required"
/>
<xs:attribute
name=
"table"
type=
"xs:NMTOKEN"
/>
<xs:attribute
name=
"schema"
type=
"xs:NMTOKEN"
/>
<xs:attribute
name=
"inheritance-type"
type=
"orm:inheritance-type"
/>
</xs:complexType>
<xs:complexType
name=
"mapped-superclass"
>
<xs:sequence>
<xs:element
name=
"id"
type=
"orm:id"
minOccurs=
"0"
/>
<xs:element
name=
"field"
type=
"orm:field"
minOccurs=
"0"
/>
<xs:element
name=
"one-to-many"
type=
"orm:one-to-many"
minOccurs=
"0"
/>
<xs:element
name=
"many-to-many"
type=
"orm:many-to-many"
minOccurs=
"0"
/>
</xs:sequence>
<xs:attribute
name=
"name"
type=
"xs:NMTOKEN"
use=
"required"
/>
</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>
</xs:simpleType>
<xs:complexType
name=
"field"
>
<xs:attribute
name=
"name"
type=
"xs:NMTOKEN"
use=
"required"
/>
<xs:attribute
name=
"type"
type=
"xs:NMTOKEN"
use=
"required"
/>
<xs:attribute
name=
"column"
type=
"xs:NMTOKEN"
/>
<xs:attribute
name=
"length"
type=
"xs:NMTOKEN"
/>
</xs:complexType>
<xs:complexType
name=
"generator"
>
<xs:attribute
name=
"strategy"
type=
"xs:NMTOKEN"
use=
"required"
/>
</xs:complexType>
<xs:complexType
name=
"id"
>
<xs:sequence>
<xs:element
name=
"generator"
type=
"orm:generator"
minOccurs=
"0"
/>
</xs:sequence>
<xs:attribute
name=
"name"
type=
"xs:NMTOKEN"
use=
"required"
/>
<xs:attribute
name=
"type"
type=
"xs:NMTOKEN"
use=
"required"
/>
<xs:attribute
name=
"column"
type=
"xs:NMTOKEN"
/>
</xs:complexType>
<xs:complexType
name=
"inverse-join-columns"
>
<xs:sequence>
<xs:element
name=
"join-column"
type=
"orm:join-column"
/>
</xs:sequence>
</xs:complexType>
<xs:complexType
name=
"join-column"
>
<xs:attribute
name=
"name"
type=
"xs:NMTOKEN"
use=
"required"
/>
<xs:attribute
name=
"referencedColumnName"
type=
"xs:NMTOKEN"
use=
"required"
/>
</xs:complexType>
<xs:complexType
name=
"join-columns"
>
<xs:sequence>
<xs:element
name=
"join-column"
type=
"orm:join-column"
/>
</xs:sequence>
</xs:complexType>
<xs:complexType
name=
"join-table"
>
<xs:sequence>
<xs:element
name=
"join-columns"
type=
"orm:join-columns"
/>
<xs:element
name=
"inverse-join-columns"
type=
"orm:join-columns"
/>
</xs:sequence>
<xs:attribute
name=
"name"
type=
"xs:NMTOKEN"
use=
"required"
/>
</xs:complexType>
<xs:complexType
name=
"many-to-many"
>
<xs:sequence>
<xs:element
name=
"cascade"
type=
"orm:cascade-type"
minOccurs=
"0"
/>
<xs:element
name=
"join-table"
type=
"orm:join-table"
/>
</xs:sequence>
<xs:attribute
name=
"targetEntity"
type=
"xs:NMTOKEN"
use=
"required"
/>
<xs:attribute
name=
"field"
type=
"xs:NMTOKEN"
use=
"required"
/>
</xs:complexType>
<xs:complexType
name=
"one-to-many"
>
<xs:sequence>
<xs:element
name=
"cascade"
type=
"orm:cascade-type"
minOccurs=
"0"
/>
</xs:sequence>
<xs:attribute
name=
"targetEntity"
type=
"xs:NMTOKEN"
use=
"required"
/>
<xs:attribute
name=
"mappedBy"
type=
"xs:NMTOKEN"
/>
<xs:attribute
name=
"field"
type=
"xs:NMTOKEN"
use=
"required"
/>
</xs:complexType>
<xs:complexType
name=
"one-to-one"
>
<xs:sequence>
<xs:element
name=
"cascade"
type=
"orm:cascade-type"
minOccurs=
"0"
/>
<xs:choice
minOccurs=
"0"
maxOccurs=
"1"
>
<xs:element
name=
"join-column"
type=
"orm:join-column"
/>
<xs:element
name=
"join-columns"
type=
"orm:join-columns"
/>
</xs:choice>
</xs:sequence>
<xs:attribute
name=
"targetEntity"
type=
"xs:NMTOKEN"
use=
"required"
/>
<xs:attribute
name=
"mappedBy"
type=
"xs:NMTOKEN"
/>
<xs:attribute
name=
"field"
type=
"xs:NMTOKEN"
use=
"required"
/>
</xs:complexType>
</xs:schema>
\ No newline at end of file
lib/Doctrine/Common/ClassLoader.php
View file @
d90e71d0
...
@@ -59,7 +59,7 @@ class ClassLoader
...
@@ -59,7 +59,7 @@ class ClassLoader
}
}
/**
/**
* Set
namespace separator
* Set
s the namespace separator to use.
*
*
* @param string $separator
* @param string $separator
* @return void
* @return void
...
...
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
View file @
d90e71d0
...
@@ -66,12 +66,10 @@ class ClassMetadataFactory
...
@@ -66,12 +66,10 @@ class ClassMetadataFactory
public
function
setCacheDriver
(
$cacheDriver
)
public
function
setCacheDriver
(
$cacheDriver
)
{
{
$this
->
_cacheDriver
=
$cacheDriver
;
$this
->
_cacheDriver
=
$cacheDriver
;
/*
foreach
(
$this
->
_driver
->
preload
()
as
$className
)
{
foreach
(
$this
->
_driver
->
preload
()
as
$className
)
{
$cacheKey
=
"
$className
\$
CLASSMETADATA"
;
$cacheKey
=
"
$className
\$
CLASSMETADATA"
;
$this
->
_cacheDriver
->
save
(
$cacheKey
,
$this
->
getMetadataFor
(
$className
),
null
);
$this
->
_cacheDriver
->
save
(
$cacheKey
,
$this
->
getMetadataFor
(
$className
),
null
);
}
}
*/
}
}
/**
/**
...
...
lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
View file @
d90e71d0
...
@@ -61,12 +61,12 @@ class AnnotationDriver
...
@@ -61,12 +61,12 @@ class AnnotationDriver
));
));
}
}
// Evaluate
Doctrine
InheritanceType annotation
// Evaluate InheritanceType annotation
if
(
$inheritanceTypeAnnot
=
$annotClass
->
getAnnotation
(
'InheritanceType'
))
{
if
(
$inheritanceTypeAnnot
=
$annotClass
->
getAnnotation
(
'InheritanceType'
))
{
$metadata
->
setInheritanceType
(
$inheritanceTypeAnnot
->
value
);
$metadata
->
setInheritanceType
(
$inheritanceTypeAnnot
->
value
);
}
}
// Evaluate D
octrineD
iscriminatorColumn annotation
// Evaluate DiscriminatorColumn annotation
if
(
$discrColumnAnnot
=
$annotClass
->
getAnnotation
(
'DiscriminatorColumn'
))
{
if
(
$discrColumnAnnot
=
$annotClass
->
getAnnotation
(
'DiscriminatorColumn'
))
{
$metadata
->
setDiscriminatorColumn
(
array
(
$metadata
->
setDiscriminatorColumn
(
array
(
'name'
=>
$discrColumnAnnot
->
name
,
'name'
=>
$discrColumnAnnot
->
name
,
...
@@ -75,7 +75,7 @@ class AnnotationDriver
...
@@ -75,7 +75,7 @@ class AnnotationDriver
));
));
}
}
// Evaluate D
octrineDiscriminatorMap
annotation
// Evaluate D
iscriminatorValue
annotation
if
(
$discrValueAnnot
=
$annotClass
->
getAnnotation
(
'DiscriminatorValue'
))
{
if
(
$discrValueAnnot
=
$annotClass
->
getAnnotation
(
'DiscriminatorValue'
))
{
$metadata
->
setDiscriminatorValue
(
$discrValueAnnot
->
value
);
$metadata
->
setDiscriminatorValue
(
$discrValueAnnot
->
value
);
}
}
...
...
lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
0 → 100644
View file @
d90e71d0
This diff is collapsed.
Click to expand it.
lib/Doctrine/ORM/Mapping/OneToOneMapping.php
View file @
d90e71d0
...
@@ -89,7 +89,7 @@ class OneToOneMapping extends AssociationMapping
...
@@ -89,7 +89,7 @@ class OneToOneMapping extends AssociationMapping
if
(
$this
->
isOwningSide
())
{
if
(
$this
->
isOwningSide
())
{
if
(
!
isset
(
$mapping
[
'joinColumns'
]))
{
if
(
!
isset
(
$mapping
[
'joinColumns'
]))
{
throw
MappingException
::
invalidMapping
(
$this
->
_
sourceFieldName
);
throw
MappingException
::
invalidMapping
(
$this
->
sourceFieldName
);
}
}
$this
->
joinColumns
=
$mapping
[
'joinColumns'
];
$this
->
joinColumns
=
$mapping
[
'joinColumns'
];
foreach
(
$mapping
[
'joinColumns'
]
as
$joinColumn
)
{
foreach
(
$mapping
[
'joinColumns'
]
as
$joinColumn
)
{
...
...
tests/Doctrine/Tests/ORM/Mapping/AllTests.php
View file @
d90e71d0
...
@@ -20,6 +20,7 @@ class AllTests
...
@@ -20,6 +20,7 @@ class AllTests
$suite
=
new
\Doctrine\Tests\DoctrineTestSuite
(
'Doctrine Orm Mapping'
);
$suite
=
new
\Doctrine\Tests\DoctrineTestSuite
(
'Doctrine Orm Mapping'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Mapping\ClassMetadataTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Mapping\ClassMetadataTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Mapping\XmlDriverTest'
);
//$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataFactoryTest');
//$suite->addTestSuite('Doctrine\Tests\ORM\Mapping\ClassMetadataFactoryTest');
return
$suite
;
return
$suite
;
...
...
tests/Doctrine/Tests/ORM/Mapping/XmlDriverTest.php
0 → 100644
View file @
d90e71d0
<?php
namespace
Doctrine\Tests\ORM\Mapping
;
use
Doctrine\ORM\Mapping\ClassMetadata
;
use
Doctrine\ORM\Mapping\Driver\XmlDriver
;
require_once
__DIR__
.
'/xml/User.php'
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
XmlDriverTest
extends
\Doctrine\Tests\OrmTestCase
{
public
function
testFilePerClassMapping
()
{
$className
=
'XmlMappingTest\User'
;
$xmlDriver
=
new
XmlDriver
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'xml'
,
XmlDriver
::
FILE_PER_CLASS
);
$class
=
new
ClassMetadata
(
$className
);
$this
->
assertFalse
(
$xmlDriver
->
isTransient
(
$className
));
$xmlDriver
->
loadMetadataForClass
(
$className
,
$class
);
$this
->
assertEquals
(
'cms_users'
,
$class
->
getTableName
());
$this
->
assertEquals
(
ClassMetadata
::
INHERITANCE_TYPE_NONE
,
$class
->
getInheritanceType
());
$this
->
assertEquals
(
2
,
count
(
$class
->
fieldMappings
));
$this
->
assertTrue
(
isset
(
$class
->
fieldMappings
[
'id'
]));
$this
->
assertTrue
(
isset
(
$class
->
fieldMappings
[
'name'
]));
$this
->
assertEquals
(
'string'
,
$class
->
fieldMappings
[
'name'
][
'type'
]);
$this
->
assertEquals
(
array
(
'id'
),
$class
->
identifier
);
$this
->
assertEquals
(
ClassMetadata
::
GENERATOR_TYPE_AUTO
,
$class
->
getIdGeneratorType
());
$this
->
assertEquals
(
3
,
count
(
$class
->
associationMappings
));
$this
->
assertEquals
(
1
,
count
(
$class
->
inverseMappings
));
$this
->
assertTrue
(
$class
->
associationMappings
[
'address'
]
instanceof
\Doctrine\ORM\Mapping\OneToOneMapping
);
$this
->
assertTrue
(
isset
(
$class
->
associationMappings
[
'address'
]));
$this
->
assertTrue
(
$class
->
associationMappings
[
'address'
]
->
isOwningSide
);
$this
->
assertTrue
(
$class
->
associationMappings
[
'phonenumbers'
]
instanceof
\Doctrine\ORM\Mapping\OneToManyMapping
);
$this
->
assertTrue
(
isset
(
$class
->
associationMappings
[
'phonenumbers'
]));
$this
->
assertFalse
(
$class
->
associationMappings
[
'phonenumbers'
]
->
isOwningSide
);
$this
->
assertTrue
(
$class
->
associationMappings
[
'phonenumbers'
]
->
isInverseSide
());
$this
->
assertTrue
(
$class
->
associationMappings
[
'phonenumbers'
]
->
isCascadeSave
);
$this
->
assertTrue
(
$class
->
associationMappings
[
'groups'
]
instanceof
\Doctrine\ORM\Mapping\ManyToManyMapping
);
$this
->
assertTrue
(
isset
(
$class
->
associationMappings
[
'groups'
]));
$this
->
assertTrue
(
$class
->
associationMappings
[
'groups'
]
->
isOwningSide
);
}
public
function
testPreloadMode
()
{
$className
=
'XmlMappingTest\User'
;
$xmlDriver
=
new
XmlDriver
(
__DIR__
.
DIRECTORY_SEPARATOR
.
'xml'
);
$class
=
new
ClassMetadata
(
$className
);
$classNames
=
$xmlDriver
->
preload
();
$this
->
assertEquals
(
$className
,
$classNames
[
0
]);
$this
->
assertEquals
(
1
,
count
(
$xmlDriver
->
getPreloadedXmlElements
()));
$xmlDriver
->
loadMetadataForClass
(
$className
,
$class
);
$this
->
assertEquals
(
0
,
count
(
$xmlDriver
->
getPreloadedXmlElements
()));
}
}
\ No newline at end of file
tests/Doctrine/Tests/ORM/Mapping/xml/User.php
0 → 100644
View file @
d90e71d0
<?php
namespace
XmlMappingTest
;
class
User
{
private
$id
;
private
$name
;
private
$address
;
private
$phonenumbers
;
private
$groups
;
// ... rest of code omitted, irrelevant for the mapping test
}
tests/Doctrine/Tests/ORM/Mapping/xml/XmlMappingTest.User.dcm.xml
0 → 100644
View file @
d90e71d0
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping
xmlns=
"http://schemas.doctrine-project.org/orm/doctrine-mapping"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://schemas.doctrine-project.org/orm/doctrine-mapping
/Users/robo/dev/php/Doctrine/doctrine-mapping.xsd"
>
<entity
name=
"XmlMappingTest\User"
table=
"cms_users"
>
<id
name=
"id"
type=
"integer"
column=
"id"
>
<generator
strategy=
"auto"
/>
</id>
<field
name=
"name"
column=
"name"
type=
"string"
length=
"50"
/>
<one-to-one
field=
"address"
targetEntity=
"Address"
>
<join-column
name=
"address_id"
referencedColumnName=
"id"
/>
</one-to-one>
<one-to-many
field=
"phonenumbers"
targetEntity=
"Phonenumber"
mappedBy=
"user"
>
<cascade>
<cascade-save/>
</cascade>
</one-to-many>
<many-to-many
field=
"groups"
targetEntity=
"Group"
>
<join-table
name=
"cms_users_groups"
>
<join-columns>
<join-column
name=
"user_id"
referencedColumnName=
"id"
/>
</join-columns>
<inverse-join-columns>
<join-column
name=
"group_id"
referencedColumnName=
"id"
/>
</inverse-join-columns>
</join-table>
</many-to-many>
</entity>
</doctrine-mapping>
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