Commit ceb05e85 authored by Jonathan H. Wage's avatar Jonathan H. Wage

Removing ClassMetadataReader

parent bce7ebfc
This diff is collapsed.
......@@ -62,7 +62,7 @@ class ConvertDoctrine1Schema
*
* @return array $metadatas An array of ClassMetadataInfo instances
*/
public function getMetadatas()
public function getMetadata()
{
$schema = array();
foreach ($this->_from as $path) {
......
......@@ -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
......@@ -36,7 +36,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
*/
abstract class AbstractExporter
{
protected $_metadatas = 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 $metadatas
* @param array $metadata
* @return void
*/
public function setMetadatas(array $metadatas)
public function setMetadata(array $metadata)
{
$this->_metadatas = $metadatas;
$this->_metadata = $metadata;
}
/**
......@@ -79,7 +79,7 @@ abstract class AbstractExporter
* Set the directory to output the mapping files to
*
* [php]
* $exporter = new YamlExporter($metadatas);
* $exporter = new YamlExporter($metadata);
* $exporter->setOutputDir(__DIR__ . '/yaml');
* $exporter->export();
*
......@@ -103,7 +103,7 @@ abstract class AbstractExporter
mkdir($this->_outputDir, 0777, true);
}
foreach ($this->_metadatas 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($metadatas, __DIR__ . '/yaml');
* $exporter = new YamlExporter($metadata, __DIR__ . '/yaml');
* $exporter->setExtension('.yml');
* $exporter->export();
*
......
......@@ -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;
}
}
......
......@@ -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->setMetadatas($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($metadatas));
$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');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment