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
ceb05e85
Commit
ceb05e85
authored
Apr 14, 2010
by
Jonathan H. Wage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removing ClassMetadataReader
parent
bce7ebfc
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
203 additions
and
517 deletions
+203
-517
ClassMetadataReader.php
lib/Doctrine/ORM/Tools/ClassMetadataReader.php
+0
-287
ConvertDoctrine1Schema.php
lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php
+1
-1
ClassMetadataExporter.php
lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php
+3
-66
AbstractExporter.php
lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php
+7
-7
DatabaseDriverTest.php
tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php
+7
-11
ConvertDoctrine1SchemaTest.php
...s/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php
+42
-17
AbstractClassMetadataExporterTest.php
...ts/ORM/Tools/Export/AbstractClassMetadataExporterTest.php
+143
-128
No files found.
lib/Doctrine/ORM/Tools/ClassMetadataReader.php
deleted
100644 → 0
View file @
bce7ebfc
This diff is collapsed.
Click to expand it.
lib/Doctrine/ORM/Tools/ConvertDoctrine1Schema.php
View file @
ceb05e85
...
...
@@ -62,7 +62,7 @@ class ConvertDoctrine1Schema
*
* @return array $metadatas An array of ClassMetadataInfo instances
*/
public
function
getMetadata
s
()
public
function
getMetadata
()
{
$schema
=
array
();
foreach
(
$this
->
_from
as
$path
)
{
...
...
lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php
View file @
ceb05e85
...
...
@@ -22,29 +22,13 @@
namespace
Doctrine\ORM\Tools\Export
;
use
Doctrine\ORM\Tools\ClassMetadataReader
,
Doctrine\ORM\Tools\Export\ExportException
,
use
Doctrine\ORM\Tools\Export\ExportException
,
Doctrine\ORM\EntityManager
;
/**
* Class used for converting your mapping information between the
* supported formats: yaml, xml, and php/annotation.
*
* [php]
* // Unify all your mapping information which is written in php, xml, yml
* // and convert it to a single set of yaml files.
*
* $cme = new Doctrine\ORM\Tools\Export\ClassMetadataExporter();
* $cme->addMappingSource(__DIR__ . '/Entities');
* $cme->addMappingSource(__DIR__ . '/xml');
* $cme->addMappingSource(__DIR__ . '/yaml');
*
* $exporter = $cme->getExporter('yaml');
* $exporter->setOutputDir(__DIR__ . '/new_yaml');
*
* $exporter->setMetadatas($cme->getMetadatas());
* $exporter->export();
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
...
...
@@ -61,11 +45,6 @@ class ClassMetadataExporter
'annotation'
=>
'Doctrine\ORM\Tools\Export\Driver\AnnotationExporter'
);
public
function
__construct
()
{
$this
->
_reader
=
new
ClassMetadataReader
();
}
/**
* Register a new exporter driver class under a specified name
*
...
...
@@ -77,18 +56,6 @@ class ClassMetadataExporter
self
::
$_exporterDrivers
[
$name
]
=
$class
;
}
/**
* Optionally set the EntityManager instance to get the AnnotationDriver
* from instead of creating a new instance of the AnnotationDriver
*
* @param EntityManager $em
* @return void
*/
public
function
setEntityManager
(
EntityManager
$em
)
{
$this
->
_reader
->
setEntityManager
(
$em
);
}
/**
* Get a exporter driver instance
*
...
...
@@ -96,7 +63,7 @@ class ClassMetadataExporter
* @param string $source The directory where the exporter will export to
* @return AbstractExporter $exporter
*/
public
function
getExporter
(
$type
,
$
source
=
null
)
public
function
getExporter
(
$type
,
$
dest
)
{
if
(
!
isset
(
self
::
$_exporterDrivers
[
$type
]))
{
throw
ExportException
::
invalidExporterDriverType
(
$type
);
...
...
@@ -104,36 +71,6 @@ class ClassMetadataExporter
$class
=
self
::
$_exporterDrivers
[
$type
];
return
new
$class
(
$source
);
}
/**
* Add a new mapping directory to the array of directories to convert and export
* to another format
*
* [php]
* $cme = new Doctrine\ORM\Tools\Export\ClassMetadataExporter();
* $cme->addMappingSource(__DIR__ . '/yaml');
* $cme->addMappingSource($schemaManager);
*
* @param string $source The source for the mapping files
* @param string $type The type of mapping files (yml, xml, etc.)
* @return void
*/
public
function
addMappingSource
(
$source
,
$type
=
null
)
{
$this
->
_reader
->
addMappingSource
(
$source
,
$type
);
}
/**
* Get an array of ClassMetadataInfo instances for all the configured mapping
* directories. Reads the mapping directories and populates ClassMetadataInfo
* instances.
*
* @return array $classes
*/
public
function
getMetadatas
()
{
return
$this
->
_reader
->
getMetadatas
();
return
new
$class
(
$dest
);
}
}
\ No newline at end of file
lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php
View file @
ceb05e85
...
...
@@ -36,7 +36,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
*/
abstract
class
AbstractExporter
{
protected
$_metadata
s
=
array
();
protected
$_metadata
=
array
();
protected
$_outputDir
;
protected
$_extension
;
...
...
@@ -57,12 +57,12 @@ abstract class AbstractExporter
/**
* Set the array of ClassMetadataInfo instances to export
*
* @param array $metadata
s
* @param array $metadata
* @return void
*/
public
function
setMetadata
s
(
array
$metadatas
)
public
function
setMetadata
(
array
$metadata
)
{
$this
->
_metadata
s
=
$metadatas
;
$this
->
_metadata
=
$metadata
;
}
/**
...
...
@@ -79,7 +79,7 @@ abstract class AbstractExporter
* Set the directory to output the mapping files to
*
* [php]
* $exporter = new YamlExporter($metadata
s
);
* $exporter = new YamlExporter($metadata);
* $exporter->setOutputDir(__DIR__ . '/yaml');
* $exporter->export();
*
...
...
@@ -103,7 +103,7 @@ abstract class AbstractExporter
mkdir
(
$this
->
_outputDir
,
0777
,
true
);
}
foreach
(
$this
->
_metadata
s
as
$metadata
)
{
foreach
(
$this
->
_metadata
as
$metadata
)
{
$output
=
$this
->
exportClassMetadata
(
$metadata
);
$path
=
$this
->
_generateOutputPath
(
$metadata
);
$dir
=
dirname
(
$path
);
...
...
@@ -129,7 +129,7 @@ abstract class AbstractExporter
* Set the directory to output the mapping files to
*
* [php]
* $exporter = new YamlExporter($metadata
s
, __DIR__ . '/yaml');
* $exporter = new YamlExporter($metadata, __DIR__ . '/yaml');
* $exporter->setExtension('.yml');
* $exporter->export();
*
...
...
tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php
View file @
ceb05e85
...
...
@@ -4,7 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
require_once
__DIR__
.
'/../../TestInit.php'
;
use
Doctrine\ORM\
Tools\ClassMetadataReader
;
use
Doctrine\ORM\
Mapping\ClassMetadataInfo
;
class
DatabaseDriverTest
extends
\Doctrine\Tests\OrmFunctionalTestCase
{
...
...
@@ -80,7 +80,6 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
assertType
(
'Doctrine\ORM\Mapping\OneToOneMapping'
,
$metadata
->
associationMappings
[
'bar'
]);
}
/**
*
* @param string $className
...
...
@@ -88,15 +87,12 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/
protected
function
extractClassMetadata
(
$className
)
{
$cm
=
new
ClassMetadataReader
();
$cm
->
addMappingSource
(
new
\Doctrine\ORM\Mapping\Driver\DatabaseDriver
(
$this
->
_sm
));
$metadatas
=
$cm
->
getMetadatas
();
$output
=
false
;
foreach
(
$metadatas
AS
$metadata
)
{
if
(
strtolower
(
$metadata
->
name
)
==
strtolower
(
$className
))
{
return
$metadata
;
$driver
=
new
\Doctrine\ORM\Mapping\Driver\DatabaseDriver
(
$this
->
_sm
);
foreach
(
$driver
->
getAllClassNames
()
as
$dbClassName
)
{
$class
=
new
ClassMetadataInfo
(
$dbClassName
);
$driver
->
loadMetadataForClass
(
$dbClassName
,
$class
);
if
(
strtolower
(
$class
->
name
)
==
strtolower
(
$className
))
{
return
$class
;
}
}
...
...
tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php
View file @
ceb05e85
...
...
@@ -21,8 +21,15 @@
namespace
Doctrine\Tests\ORM\Tools
;
use
Doctrine\ORM\Tools\Export\ClassMetadataExporter
,
Doctrine\ORM\Tools\ConvertDoctrine1Schema
;
use
Doctrine\ORM\Tools\Export\ClassMetadataExporter
;
use
Doctrine\ORM\Tools\ConvertDoctrine1Schema
;
use
Doctrine\Tests\Mocks\MetadataDriverMock
;
use
Doctrine\Tests\Mocks\DatabasePlatformMock
;
use
Doctrine\Tests\Mocks\EntityManagerMock
;
use
Doctrine\Tests\Mocks\ConnectionMock
;
use
Doctrine\Tests\Mocks\DriverMock
;
use
Doctrine\Common\EventManager
;
use
Doctrine\ORM\Tools\DisconnectedClassMetadataFactory
;
require_once
__DIR__
.
'/../../TestInit.php'
;
...
...
@@ -38,9 +45,23 @@ require_once __DIR__ . '/../../TestInit.php';
*/
class
ConvertDoctrine1SchemaTest
extends
\Doctrine\Tests\OrmTestCase
{
protected
function
_createEntityManager
(
$metadataDriver
)
{
$driverMock
=
new
DriverMock
();
$config
=
new
\Doctrine\ORM\Configuration
();
$config
->
setProxyDir
(
__DIR__
.
'/../../Proxies'
);
$config
->
setProxyNamespace
(
'Doctrine\Tests\Proxies'
);
$eventManager
=
new
EventManager
();
$conn
=
new
ConnectionMock
(
array
(),
$driverMock
,
$config
,
$eventManager
);
$mockDriver
=
new
MetadataDriverMock
();
$config
->
setMetadataDriverImpl
(
$metadataDriver
);
return
EntityManagerMock
::
create
(
$conn
,
$config
,
$eventManager
);
}
public
function
testTest
()
{
if
(
!
class_exists
(
'Symfony\Components\Yaml\Yaml'
,
true
))
{
if
(
!
class_exists
(
'Symfony\Components\Yaml\Yaml'
,
true
))
{
$this
->
markTestSkipped
(
'Please install Symfony YAML Component into the include path of your PHP installation.'
);
}
...
...
@@ -48,28 +69,32 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase
$converter
=
new
ConvertDoctrine1Schema
(
__DIR__
.
'/doctrine1schema'
);
$exporter
=
$cme
->
getExporter
(
'yml'
,
__DIR__
.
'/convert'
);
$exporter
->
setMetadata
s
(
$converter
->
getMetadatas
());
$exporter
->
setMetadata
(
$converter
->
getMetadata
());
$exporter
->
export
();
$this
->
assertTrue
(
file_exists
(
__DIR__
.
'/convert/User.dcm.yml'
));
$this
->
assertTrue
(
file_exists
(
__DIR__
.
'/convert/Profile.dcm.yml'
));
$cme
->
addMappingSource
(
__DIR__
.
'/convert'
);
$metadatas
=
$cme
->
getMetadatas
();
$metadataDriver
=
new
\Doctrine\ORM\Mapping\Driver\YamlDriver
(
__DIR__
.
'/convert'
);
$em
=
$this
->
_createEntityManager
(
$metadataDriver
);
$cmf
=
new
DisconnectedClassMetadataFactory
(
$em
);
$metadata
=
$cmf
->
getAllMetadata
();
$profileClass
=
$metadata
[
0
];
$userClass
=
$metadata
[
1
];
$this
->
assertEquals
(
2
,
count
(
$metadata
s
));
$this
->
assertEquals
(
'Profile'
,
$
metadatas
[
'Profile'
]
->
name
);
$this
->
assertEquals
(
'User'
,
$
metadatas
[
'User'
]
->
name
);
$this
->
assertEquals
(
4
,
count
(
$
metadatas
[
'Profile'
]
->
fieldMappings
));
$this
->
assertEquals
(
5
,
count
(
$
metadatas
[
'User'
]
->
fieldMappings
));
$this
->
assertEquals
(
'text'
,
$
metadatas
[
'User'
]
->
fieldMappings
[
'clob'
][
'type'
]);
$this
->
assertEquals
(
'test_alias'
,
$
metadatas
[
'User'
]
->
fieldMappings
[
'theAlias'
][
'columnName'
]);
$this
->
assertEquals
(
'theAlias'
,
$
metadatas
[
'User'
]
->
fieldMappings
[
'theAlias'
][
'fieldName'
]);
$this
->
assertEquals
(
2
,
count
(
$metadata
));
$this
->
assertEquals
(
'Profile'
,
$
profileClass
->
name
);
$this
->
assertEquals
(
'User'
,
$
userClass
->
name
);
$this
->
assertEquals
(
4
,
count
(
$
profileClass
->
fieldMappings
));
$this
->
assertEquals
(
5
,
count
(
$
userClass
->
fieldMappings
));
$this
->
assertEquals
(
'text'
,
$
userClass
->
fieldMappings
[
'clob'
][
'type'
]);
$this
->
assertEquals
(
'test_alias'
,
$
userClass
->
fieldMappings
[
'theAlias'
][
'columnName'
]);
$this
->
assertEquals
(
'theAlias'
,
$
userClass
->
fieldMappings
[
'theAlias'
][
'fieldName'
]);
$this
->
assertEquals
(
'Profile'
,
$
metadatas
[
'Profile'
]
->
associationMappings
[
'User'
]
->
sourceEntityName
);
$this
->
assertEquals
(
'User'
,
$
metadatas
[
'Profile'
]
->
associationMappings
[
'User'
]
->
targetEntityName
);
$this
->
assertEquals
(
'Profile'
,
$
profileClass
->
associationMappings
[
'User'
]
->
sourceEntityName
);
$this
->
assertEquals
(
'User'
,
$
profileClass
->
associationMappings
[
'User'
]
->
targetEntityName
);
$this
->
assertEquals
(
'username'
,
$
metadatas
[
'User'
]
->
table
[
'uniqueConstraints'
][
'username'
][
'columns'
][
0
]);
$this
->
assertEquals
(
'username'
,
$
userClass
->
table
[
'uniqueConstraints'
][
'username'
][
'columns'
][
0
]);
unlink
(
__DIR__
.
'/convert/User.dcm.yml'
);
unlink
(
__DIR__
.
'/convert/Profile.dcm.yml'
);
...
...
tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php
View file @
ceb05e85
This diff is collapsed.
Click to expand it.
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