Commit d1b2f93a authored by jwage's avatar jwage

[2.0] Splitting ClassMetadata in to ClassMetadataInfo and other bug fixes

parent 968ebb80
...@@ -108,7 +108,6 @@ class IsolatedClassLoader ...@@ -108,7 +108,6 @@ class IsolatedClassLoader
$class = ($this->_basePath !== null ? $this->_basePath . DIRECTORY_SEPARATOR : '') $class = ($this->_basePath !== null ? $this->_basePath . DIRECTORY_SEPARATOR : '')
. str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $className) . str_replace($this->_namespaceSeparator, DIRECTORY_SEPARATOR, $className)
. $this->_fileExtension; . $this->_fileExtension;
require $class; require $class;
return true; return true;
......
...@@ -472,7 +472,7 @@ class EntityManager ...@@ -472,7 +472,7 @@ class EntityManager
$metadata = $this->getClassMetadata($entityName); $metadata = $this->getClassMetadata($entityName);
$customRepositoryClassName = $metadata->getCustomRepositoryClass(); $customRepositoryClassName = $metadata->getCustomRepositoryClass();
if ($customRepositoryClassName !== null) { if ($customRepositoryClassName !== null) {
$repository = new $customRepositoryClassName($entityName, $metadata); $repository = new $customRepositoryClassName($this, $metadata);
} else { } else {
$repository = new EntityRepository($this, $metadata); $repository = new EntityRepository($this, $metadata);
} }
......
...@@ -35,9 +35,9 @@ namespace Doctrine\ORM; ...@@ -35,9 +35,9 @@ namespace Doctrine\ORM;
*/ */
class EntityRepository class EntityRepository
{ {
private $_entityName; protected $_entityName;
private $_em; protected $_em;
private $_class; protected $_class;
/** /**
* Initializes a new <tt>EntityRepository</tt>. * Initializes a new <tt>EntityRepository</tt>.
......
This diff is collapsed.
...@@ -319,14 +319,12 @@ class ClassMetadataFactory ...@@ -319,14 +319,12 @@ class ClassMetadataFactory
if ($assoc->isOneToOne() && $assoc->isOwningSide) { if ($assoc->isOneToOne() && $assoc->isOwningSide) {
foreach ($assoc->targetToSourceKeyColumns as $sourceCol) { foreach ($assoc->targetToSourceKeyColumns as $sourceCol) {
$columns[] = $assoc->getQuotedJoinColumnName($sourceCol, $this->_targetPlatform); $columns[] = $assoc->getQuotedJoinColumnName($sourceCol, $this->_targetPlatform);
$values[] = '?';
// Add column mapping for SQL result sets // Add column mapping for SQL result sets
$class->resultColumnNames[$this->_targetPlatform->getSqlResultCasing($sourceCol)] = $sourceCol; $class->resultColumnNames[$this->_targetPlatform->getSqlResultCasing($sourceCol)] = $sourceCol;
} }
} }
} else if ($class->name != $class->rootEntityName || ! $class->isIdGeneratorIdentity() || $class->identifier[0] != $name) { } else if ($class->name != $class->rootEntityName || ! $class->isIdGeneratorIdentity() || $class->identifier[0] != $name) {
$columns[] = $class->getQuotedColumnName($name, $this->_targetPlatform); $columns[] = $class->getQuotedColumnName($name, $this->_targetPlatform);
$values[] = '?';
// Add column mapping for SQL result sets // Add column mapping for SQL result sets
$columnName = $class->columnNames[$name]; $columnName = $class->columnNames[$name];
$class->resultColumnNames[$this->_targetPlatform->getSqlResultCasing($columnName)] = $columnName; $class->resultColumnNames[$this->_targetPlatform->getSqlResultCasing($columnName)] = $columnName;
...@@ -347,14 +345,12 @@ class ClassMetadataFactory ...@@ -347,14 +345,12 @@ class ClassMetadataFactory
if ($assoc->isOwningSide && $assoc->isOneToOne()) { if ($assoc->isOwningSide && $assoc->isOneToOne()) {
foreach ($assoc->targetToSourceKeyColumns as $sourceCol) { foreach ($assoc->targetToSourceKeyColumns as $sourceCol) {
$columns[] = $assoc->getQuotedJoinColumnName($sourceCol, $this->_targetPlatform); $columns[] = $assoc->getQuotedJoinColumnName($sourceCol, $this->_targetPlatform);
$values[] = '?';
// Add column mapping for SQL result sets // Add column mapping for SQL result sets
$class->resultColumnNames[$this->_targetPlatform->getSqlResultCasing($sourceCol)] = $sourceCol; $class->resultColumnNames[$this->_targetPlatform->getSqlResultCasing($sourceCol)] = $sourceCol;
} }
} }
} else if ($class->generatorType != ClassMetadata::GENERATOR_TYPE_IDENTITY || $class->identifier[0] != $name) { } else if ($class->generatorType != ClassMetadata::GENERATOR_TYPE_IDENTITY || $class->identifier[0] != $name) {
$columns[] = $class->getQuotedColumnName($name, $this->_targetPlatform); $columns[] = $class->getQuotedColumnName($name, $this->_targetPlatform);
$values[] = '?';
// Add column mapping for SQL result sets // Add column mapping for SQL result sets
$columnName = $class->columnNames[$name]; $columnName = $class->columnNames[$name];
$class->resultColumnNames[$this->_targetPlatform->getSqlResultCasing($columnName)] = $columnName; $class->resultColumnNames[$this->_targetPlatform->getSqlResultCasing($columnName)] = $columnName;
...@@ -371,7 +367,6 @@ class ClassMetadataFactory ...@@ -371,7 +367,6 @@ class ClassMetadataFactory
if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined() if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()
&& $class->name == $class->rootEntityName) { && $class->name == $class->rootEntityName) {
$columns[] = $class->getQuotedDiscriminatorColumnName($this->_targetPlatform); $columns[] = $class->getQuotedDiscriminatorColumnName($this->_targetPlatform);
$values[] = '?';
} }
// Add column mapping for SQL result sets // Add column mapping for SQL result sets
$columnName = $class->discriminatorColumn['name']; $columnName = $class->discriminatorColumn['name'];
...@@ -384,6 +379,9 @@ class ClassMetadataFactory ...@@ -384,6 +379,9 @@ class ClassMetadataFactory
$class->getQuotedColumnName($class->identifier[0], $this->_targetPlatform) $class->getQuotedColumnName($class->identifier[0], $this->_targetPlatform)
); );
} else { } else {
$columns = array_unique($columns);
$values = array_fill(0, count($columns), '?');
$class->insertSql = 'INSERT INTO ' . $class->insertSql = 'INSERT INTO ' .
$class->getQuotedTableName($this->_targetPlatform) $class->getQuotedTableName($this->_targetPlatform)
. ' (' . implode(', ', $columns) . ') ' . ' (' . implode(', ', $columns) . ') '
......
This diff is collapsed.
...@@ -24,7 +24,7 @@ namespace Doctrine\ORM\Mapping\Driver; ...@@ -24,7 +24,7 @@ namespace Doctrine\ORM\Mapping\Driver;
use Doctrine\Common\DoctrineException, use Doctrine\Common\DoctrineException,
Doctrine\Common\Cache\ArrayCache, Doctrine\Common\Cache\ArrayCache,
Doctrine\Common\Annotations\AnnotationReader, Doctrine\Common\Annotations\AnnotationReader,
Doctrine\ORM\Mapping\ClassMetadata, Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Mapping\MappingException; Doctrine\ORM\Mapping\MappingException;
require __DIR__ . '/DoctrineAnnotations.php'; require __DIR__ . '/DoctrineAnnotations.php';
...@@ -59,7 +59,7 @@ class AnnotationDriver implements Driver ...@@ -59,7 +59,7 @@ class AnnotationDriver implements Driver
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function loadMetadataForClass($className, ClassMetadata $metadata) public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{ {
$class = $metadata->getReflectionClass(); $class = $metadata->getReflectionClass();
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace Doctrine\ORM\Mapping\Driver; namespace Doctrine\ORM\Mapping\Driver;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataInfo;
/** /**
* Contract for metadata drivers. * Contract for metadata drivers.
...@@ -38,9 +38,9 @@ interface Driver ...@@ -38,9 +38,9 @@ interface Driver
* Loads the metadata for the specified class into the provided container. * Loads the metadata for the specified class into the provided container.
* *
* @param string $className * @param string $className
* @param ClassMetadata $metadata * @param ClassMetadataInfo $metadata
*/ */
public function loadMetadataForClass($className, ClassMetadata $metadata); public function loadMetadataForClass($className, ClassMetadataInfo $metadata);
/** /**
* Whether the class with the specified name should have its metadata loaded. * Whether the class with the specified name should have its metadata loaded.
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace Doctrine\ORM\Mapping\Driver; namespace Doctrine\ORM\Mapping\Driver;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataInfo;
/** /**
* XmlDriver is a metadata driver that enables mapping through XML files. * XmlDriver is a metadata driver that enables mapping through XML files.
...@@ -44,10 +44,8 @@ class XmlDriver extends AbstractFileDriver ...@@ -44,10 +44,8 @@ class XmlDriver extends AbstractFileDriver
* @param string $className * @param string $className
* @param ClassMetadata $metadata * @param ClassMetadata $metadata
*/ */
public function loadMetadataForClass($className, ClassMetadata $metadata) public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{ {
$class = $metadata->getReflectionClass();
$xmlRoot = $this->getElement($className); $xmlRoot = $this->getElement($className);
if ($xmlRoot->getName() == 'entity') { if ($xmlRoot->getName() == 'entity') {
...@@ -327,11 +325,7 @@ class XmlDriver extends AbstractFileDriver ...@@ -327,11 +325,7 @@ class XmlDriver extends AbstractFileDriver
// Evaluate <lifecycle-callbacks...> // Evaluate <lifecycle-callbacks...>
if (isset($xmlRoot->{'lifecycle-callbacks'})) { if (isset($xmlRoot->{'lifecycle-callbacks'})) {
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) { foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
$method = $class->getMethod((string)$lifecycleCallback['method']); $metadata->addLifecycleCallback((string)$lifecycleCallback['method'], constant('\Doctrine\ORM\Events::' . (string)$lifecycleCallback['type']));
if ($method->isPublic()) {
$metadata->addLifecycleCallback($method->getName(), constant('\Doctrine\ORM\Events::' . (string)$lifecycleCallback['type']));
}
} }
} }
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace Doctrine\ORM\Mapping\Driver; namespace Doctrine\ORM\Mapping\Driver;
use Doctrine\ORM\Mapping\ClassMetadata, use Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\Common\DoctrineException, Doctrine\Common\DoctrineException,
Doctrine\ORM\Mapping\MappingException; Doctrine\ORM\Mapping\MappingException;
...@@ -47,10 +47,8 @@ class YamlDriver extends AbstractFileDriver ...@@ -47,10 +47,8 @@ class YamlDriver extends AbstractFileDriver
{ {
protected $_fileExtension = '.dcm.yml'; protected $_fileExtension = '.dcm.yml';
public function loadMetadataForClass($className, ClassMetadata $metadata) public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
{ {
$class = $metadata->getReflectionClass();
$element = $this->getElement($className); $element = $this->getElement($className);
if ($element['type'] == 'entity') { if ($element['type'] == 'entity') {
...@@ -320,11 +318,7 @@ class YamlDriver extends AbstractFileDriver ...@@ -320,11 +318,7 @@ class YamlDriver extends AbstractFileDriver
// Evaluate lifeCycleCallbacks // Evaluate lifeCycleCallbacks
if (isset($element['lifecycleCallbacks'])) { if (isset($element['lifecycleCallbacks'])) {
foreach ($element['lifecycleCallbacks'] as $method => $type) { foreach ($element['lifecycleCallbacks'] as $method => $type) {
$method = $class->getMethod($method); $metadata->addLifecycleCallback($method, constant('\Doctrine\ORM\Events::' . $type));
if ($method->isPublic()) {
$metadata->addLifecycleCallback($method->getName(), constant('\Doctrine\ORM\Events::' . $type));
}
} }
} }
} }
......
...@@ -164,9 +164,6 @@ abstract class AbstractTask ...@@ -164,9 +164,6 @@ abstract class AbstractTask
if ( ! isset($this->_arguments['config'])) { if ( ! isset($this->_arguments['config'])) {
if (file_exists('./cli-config.php')) { if (file_exists('./cli-config.php')) {
require './cli-config.php'; require './cli-config.php';
} else {
$this->_printer->writeln('--config option or cli-config.php in the same directory required', 'ERROR');
return false;
} }
} else { } else {
require $this->_arguments['config']; require $this->_arguments['config'];
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace Doctrine\ORM\Tools\Cli\Tasks; namespace Doctrine\ORM\Tools\Cli\Tasks;
use Doctrine\ORM\Tools\Export\ClassmetadataExporter; use Doctrine\ORM\Tools\Export\ClassMetadataExporter;
/** /**
* CLI Task to convert your mapping information between the various formats * CLI Task to convert your mapping information between the various formats
...@@ -86,12 +86,14 @@ class ConvertMappingTask extends AbstractTask ...@@ -86,12 +86,14 @@ class ConvertMappingTask extends AbstractTask
$args = $this->getArguments(); $args = $this->getArguments();
$printer = $this->getPrinter(); $printer = $this->getPrinter();
if (!(isset($args['from']) && isset($args['to']) && isset($args['dest']))) if (!(isset($args['from']) && isset($args['to']) && isset($args['dest']))) {
{
$printer->writeln('You must include a value for all four options: --from, --to and --dest', 'ERROR'); $printer->writeln('You must include a value for all four options: --from, --to and --dest', 'ERROR');
return false; return false;
} }
if ($args['to'] != 'annotation' && $args['extend']) {
$printer->writeln('You can only use the --extend argument when converting to annoations.');
return false;
}
return true; return true;
} }
...@@ -100,7 +102,7 @@ class ConvertMappingTask extends AbstractTask ...@@ -100,7 +102,7 @@ class ConvertMappingTask extends AbstractTask
$printer = $this->getPrinter(); $printer = $this->getPrinter();
$args = $this->getArguments(); $args = $this->getArguments();
$cme = new ClassmetadataExporter(); $cme = new ClassMetadataExporter();
$from = (array) $args['from']; $from = (array) $args['from'];
foreach ($from as $path) { foreach ($from as $path) {
$type = $this->_determinePathType($path); $type = $this->_determinePathType($path);
...@@ -111,6 +113,12 @@ class ConvertMappingTask extends AbstractTask ...@@ -111,6 +113,12 @@ class ConvertMappingTask extends AbstractTask
} }
$exporter = $cme->getExporter($args['to']); $exporter = $cme->getExporter($args['to']);
if (isset($args['extend'])) {
$exporter->setClassToExtend($args['extend']);
}
if (isset($args['num-spaces'])) {
$exporter->setNumSpaces($args['num-spaces']);
}
$exporter->setOutputDir($args['dest']); $exporter->setOutputDir($args['dest']);
$printer->writeln(sprintf('Exporting %s mapping information to directory: "%s"', $args['to'], $args['dest']), 'INFO'); $printer->writeln(sprintf('Exporting %s mapping information to directory: "%s"', $args['to'], $args['dest']), 'INFO');
......
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM\Tools\Export;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Classmetadata;
/**
* 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->addMappingDir(__DIR__ . '/Entities', 'php');
* $cme->addMappingDir(__DIR__ . '/xml', 'xml');
* $cme->addMappingDir(__DIR__ . '/yaml', 'yaml');
*
* $exporter = $cme->getExporter('yaml');
* $exporter->setOutputDir(__DIR__ . '/new_yaml');
* $exporter->export();
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
* @author Jonathan Wage <jonwage@gmail.com>
*/
class ClassmetadataExporter
{
private $_exporterDrivers = array(
'xml' => 'Doctrine\ORM\Tools\Export\Driver\XmlExporter',
'yaml' => 'Doctrine\ORM\Tools\Export\Driver\YamlExporter',
'yml' => 'Doctrine\ORM\Tools\Export\Driver\YamlExporter',
'php' => 'Doctrine\ORM\Tools\Export\Driver\PhpExporter',
'annotation' => 'Doctrine\ORM\Tools\Export\Driver\AnnotationExporter'
);
private $_mappingDrivers = array(
'annotation' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'yaml' => 'Doctrine\ORM\Mapping\Driver\YamlDriver',
'yml' => 'Doctrine\ORM\Mapping\Driver\YamlDriver',
'xml' => 'Doctrine\ORM\Mapping\Driver\XmlDriver'
);
private $_mappingDirectories = array();
public function addMappingDir($dir, $type)
{
if ($type === 'php') {
$this->_mappingDirectories[] = array($dir, $type);
} else {
if ( ! isset($this->_mappingDrivers[$type])) {
throw DoctrineException::invalidMappingDriverType($type);
}
$class = $this->_mappingDrivers[$type];
if (is_subclass_of($class, 'Doctrine\ORM\Mapping\Driver\AbstractFileDriver')) {
$driver = new $class($dir, constant($class . '::PRELOAD'));
} else {
$reader = new \Doctrine\Common\Annotations\AnnotationReader(new \Doctrine\Common\Cache\ArrayCache);
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$driver = new $class($reader);
}
$this->_mappingDirectories[] = array($dir, $driver);
}
}
private function _getMetadataInstances()
{
$classes = array();
foreach ($this->_mappingDirectories as $d) {
list($dir, $driver) = $d;
if ($driver == 'php') {
$iter = new \FilesystemIterator($dir);
foreach ($iter as $item) {
include $item->getPathName();
$vars = get_defined_vars();
foreach ($vars as $var) {
if ($var instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
$classes[] = $var;
}
}
}
$classes = array_unique($classes);
$classes = array_values($classes);
} else {
if ($driver instanceof \Doctrine\ORM\Mapping\Driver\AnnotationDriver) {
$iter = new \FilesystemIterator($dir);
$declared = get_declared_classes();
foreach ($iter as $item) {
$baseName = $item->getBaseName();
if ($baseName[0] == '.') {
continue;
}
require_once $item->getPathName();
}
$declared = array_diff(get_declared_classes(), $declared);
foreach ($declared as $className) {
if ( ! $driver->isTransient($className)) {
$metadata = new ClassMetadata($className);
$driver->loadMetadataForClass($className, $metadata);
$classes[] = $metadata;
}
}
} else {
$preloadedClasses = $driver->preload(true);
foreach ($preloadedClasses as $className) {
$metadata = new ClassMetadata($className);
$driver->loadMetadataForClass($className, $metadata);
$classes[] = $metadata;
}
}
}
}
return $classes;
}
public function getExporter($type, $dir = null)
{
if ( ! isset($this->_exporterDrivers[$type])) {
throw DoctrineException::invalidExporterDriverType($type);
}
$class = $this->_exporterDrivers[$type];
return new $class($this->_getMetadataInstances());
}
}
\ No newline at end of file
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
namespace Doctrine\ORM\Tools\Export\Driver; namespace Doctrine\ORM\Tools\Export\Driver;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataInfo;
/** /**
* Abstract base class which is to be used for the Exporter drivers * Abstract base class which is to be used for the Exporter drivers
...@@ -101,28 +101,28 @@ abstract class AbstractExporter ...@@ -101,28 +101,28 @@ abstract class AbstractExporter
* Converts a single ClassMetadata instance to the exported format * Converts a single ClassMetadata instance to the exported format
* and returns it * and returns it
* *
* @param ClassMetadata $metadata * @param ClassMetadataInfo $metadata
* @return mixed $exported * @return mixed $exported
*/ */
abstract public function exportClassMetadata(ClassMetadata $metadata); abstract public function exportClassMetadata(ClassMetadataInfo $metadata);
protected function _getInheritanceTypeString($type) protected function _getInheritanceTypeString($type)
{ {
switch ($type) switch ($type)
{ {
case ClassMetadata::INHERITANCE_TYPE_NONE: case ClassMetadataInfo::INHERITANCE_TYPE_NONE:
return 'NONE'; return 'NONE';
break; break;
case ClassMetadata::INHERITANCE_TYPE_JOINED: case ClassMetadataInfo::INHERITANCE_TYPE_JOINED:
return 'JOINED'; return 'JOINED';
break; break;
case ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE: case ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE:
return 'SINGLE_TABLE'; return 'SINGLE_TABLE';
break; break;
case ClassMetadata::INHERITANCE_TYPE_TABLE_PER_CLASS: case ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS:
return 'PER_CLASS'; return 'PER_CLASS';
break; break;
} }
...@@ -132,15 +132,15 @@ abstract class AbstractExporter ...@@ -132,15 +132,15 @@ abstract class AbstractExporter
{ {
switch ($policy) switch ($policy)
{ {
case ClassMetadata::CHANGETRACKING_DEFERRED_IMPLICIT: case ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT:
return 'DEFERRED_IMPLICIT'; return 'DEFERRED_IMPLICIT';
break; break;
case ClassMetadata::CHANGETRACKING_DEFERRED_EXPLICIT: case ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT:
return 'DEFERRED_EXPLICIT'; return 'DEFERRED_EXPLICIT';
break; break;
case ClassMetadata::CHANGETRACKING_NOTIFY: case ClassMetadataInfo::CHANGETRACKING_NOTIFY:
return 'NOTIFY'; return 'NOTIFY';
break; break;
} }
...@@ -150,19 +150,19 @@ abstract class AbstractExporter ...@@ -150,19 +150,19 @@ abstract class AbstractExporter
{ {
switch ($type) switch ($type)
{ {
case ClassMetadata::GENERATOR_TYPE_AUTO: case ClassMetadataInfo::GENERATOR_TYPE_AUTO:
return 'AUTO'; return 'AUTO';
break; break;
case ClassMetadata::GENERATOR_TYPE_SEQUENCE: case ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE:
return 'SEQUENCE'; return 'SEQUENCE';
break; break;
case ClassMetadata::GENERATOR_TYPE_TABLE: case ClassMetadataInfo::GENERATOR_TYPE_TABLE:
return 'TABLE'; return 'TABLE';
break; break;
case ClassMetadata::GENERATOR_TYPE_IDENTITY: case ClassMetadataInfo::GENERATOR_TYPE_IDENTITY:
return 'IDENTITY'; return 'IDENTITY';
break; break;
} }
......
...@@ -41,10 +41,10 @@ class PhpExporter extends AbstractExporter ...@@ -41,10 +41,10 @@ class PhpExporter extends AbstractExporter
* Converts a single ClassMetadata instance to the exported format * Converts a single ClassMetadata instance to the exported format
* and returns it * and returns it
* *
* @param ClassMetadata $metadata * @param ClassMetadataInfo $metadata
* @return mixed $exported * @return mixed $exported
*/ */
public function exportClassMetadata(ClassMetadata $metadata) public function exportClassMetadata(ClassMetadataInfo $metadata)
{ {
$lines = array(); $lines = array();
$lines[] = '<?php'; $lines[] = '<?php';
......
...@@ -22,7 +22,10 @@ ...@@ -22,7 +22,10 @@
namespace Doctrine\ORM\Tools\Export\Driver; namespace Doctrine\ORM\Tools\Export\Driver;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Mapping\OneToOneMapping,
Doctrine\ORM\Mapping\OneToManyMapping,
Doctrine\ORM\Mapping\ManyToManyMapping;
/** /**
* ClassMetadata exporter for Doctrine XML mapping files * ClassMetadata exporter for Doctrine XML mapping files
...@@ -41,10 +44,10 @@ class XmlExporter extends AbstractExporter ...@@ -41,10 +44,10 @@ class XmlExporter extends AbstractExporter
* Converts a single ClassMetadata instance to the exported format * Converts a single ClassMetadata instance to the exported format
* and returns it * and returns it
* *
* @param ClassMetadata $metadata * @param ClassMetadataInfo $metadata
* @return mixed $exported * @return mixed $exported
*/ */
public function exportClassMetadata(ClassMetadata $metadata) public function exportClassMetadata(ClassMetadataInfo $metadata)
{ {
$xml = new \SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><doctrine-mapping/>"); $xml = new \SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><doctrine-mapping/>");
...@@ -170,11 +173,11 @@ class XmlExporter extends AbstractExporter ...@@ -170,11 +173,11 @@ class XmlExporter extends AbstractExporter
} }
foreach ($metadata->associationMappings as $name => $associationMapping) { foreach ($metadata->associationMappings as $name => $associationMapping) {
if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToOneMapping) { if ($associationMapping instanceof OneToOneMapping) {
$associationMappingXml = $root->addChild('one-to-one'); $associationMappingXml = $root->addChild('one-to-one');
} else if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToManyMapping) { } else if ($associationMapping instanceof OneToManyMapping) {
$associationMappingXml = $root->addChild('one-to-many'); $associationMappingXml = $root->addChild('one-to-many');
} else if ($associationMapping instanceof \Doctrine\ORM\Mapping\ManyToManyMapping) { } else if ($associationMapping instanceof ManyToManyMapping) {
$associationMappingXml = $root->addChild('many-to-many'); $associationMappingXml = $root->addChild('many-to-many');
} }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
namespace Doctrine\ORM\Tools\Export\Driver; namespace Doctrine\ORM\Tools\Export\Driver;
use Doctrine\ORM\Mapping\ClassMetadata, use Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Mapping\OneToOneMapping, Doctrine\ORM\Mapping\OneToOneMapping,
Doctrine\ORM\Mapping\OneToManyMapping, Doctrine\ORM\Mapping\OneToManyMapping,
Doctrine\ORM\Mapping\ManyToManyMapping; Doctrine\ORM\Mapping\ManyToManyMapping;
...@@ -46,10 +46,10 @@ class YamlExporter extends AbstractExporter ...@@ -46,10 +46,10 @@ class YamlExporter extends AbstractExporter
* *
* TODO: Should this code be pulled out in to a toArray() method in ClassMetadata * TODO: Should this code be pulled out in to a toArray() method in ClassMetadata
* *
* @param ClassMetadata $metadata * @param ClassMetadataInfo $metadata
* @return mixed $exported * @return mixed $exported
*/ */
public function exportClassMetadata(ClassMetadata $metadata) public function exportClassMetadata(ClassMetadataInfo $metadata)
{ {
$array = array(); $array = array();
if ($metadata->isMappedSuperclass) { if ($metadata->isMappedSuperclass) {
...@@ -114,7 +114,7 @@ class YamlExporter extends AbstractExporter ...@@ -114,7 +114,7 @@ class YamlExporter extends AbstractExporter
), ),
); );
if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToOneMapping) { if ($associationMapping instanceof OneToOneMapping) {
$oneToOneMappingArray = array( $oneToOneMappingArray = array(
'mappedBy' => $associationMapping->mappedByFieldName, 'mappedBy' => $associationMapping->mappedByFieldName,
'joinColumns' => $associationMapping->joinColumns, 'joinColumns' => $associationMapping->joinColumns,
...@@ -123,7 +123,7 @@ class YamlExporter extends AbstractExporter ...@@ -123,7 +123,7 @@ class YamlExporter extends AbstractExporter
$associationMappingArray = array_merge($associationMappingArray, $oneToOneMappingArray); $associationMappingArray = array_merge($associationMappingArray, $oneToOneMappingArray);
$array['oneToOne'][$name] = $associationMappingArray; $array['oneToOne'][$name] = $associationMappingArray;
} else if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToManyMapping) { } else if ($associationMapping instanceof OneToManyMapping) {
$oneToManyMappingArray = array( $oneToManyMappingArray = array(
'mappedBy' => $associationMapping->mappedByFieldName, 'mappedBy' => $associationMapping->mappedByFieldName,
'orphanRemoval' => $associationMapping->orphanRemoval, 'orphanRemoval' => $associationMapping->orphanRemoval,
...@@ -131,7 +131,7 @@ class YamlExporter extends AbstractExporter ...@@ -131,7 +131,7 @@ class YamlExporter extends AbstractExporter
$associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray); $associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray);
$array['oneToMany'][$name] = $associationMappingArray; $array['oneToMany'][$name] = $associationMappingArray;
} else if ($associationMapping instanceof \Doctrine\ORM\Mapping\ManyToManyMapping) { } else if ($associationMapping instanceof ManyToManyMapping) {
$manyToManyMappingArray = array( $manyToManyMappingArray = array(
'mappedBy' => $associationMapping->mappedByFieldName, 'mappedBy' => $associationMapping->mappedByFieldName,
'joinTable' => $associationMapping->joinTable, 'joinTable' => $associationMapping->joinTable,
......
[?php [?php
namespace <?php echo $metadata->namespace ?>; namespace <?php echo $this->getNamespace($metadata) ?>;
<?php if ($this->extendsClass()): ?>
use <?php echo $this->getClassToExtendNamespace() ?>;
<?php endif; ?>
/** /**
<?php if ($metadata->isMappedSuperclass): ?> <?php if ($metadata->isMappedSuperclass): ?>
...@@ -8,19 +12,10 @@ namespace <?php echo $metadata->namespace ?>; ...@@ -8,19 +12,10 @@ namespace <?php echo $metadata->namespace ?>;
<?php else: ?> <?php else: ?>
* @Entity * @Entity
<?php endif; ?> <?php endif; ?>
* <?php echo $this->_getTableAnnotation($metadata)."\n" ?> * <?php echo $this->getTableAnnotation($metadata)."\n" ?>
*/ */
class <?Php echo $metadata->getReflectionClass()->getShortName()."\n" ?> class <?Php echo $this->getClassName($metadata) ?><?php if ($this->extendsClass()): ?> extends <?php echo $this->getClassToExtendName() ?><?php endif; ?>
{
<?php foreach ($metadata->fieldMappings as $fieldMapping): ?>
<?php echo $this->_getFieldMappingAnnotation($fieldMapping, $metadata)."\n" ?>
private $<?php echo $fieldMapping['fieldName'] ?>;
<?php endforeach ?>
<?php foreach ($metadata->associationMappings as $associationMapping): ?>
<?php echo $this->_getAssociationMappingAnnotation($associationMapping, $metadata)."\n" ?>
private $<?php echo $associationMapping->sourceFieldName ?>;
<?php endforeach; ?>
{
<?php include('annotation_body.tpl.php') ?>
} }
\ No newline at end of file
...@@ -630,7 +630,6 @@ class SchemaTool ...@@ -630,7 +630,6 @@ class SchemaTool
foreach ($newJoinColumns as $name => $joinColumn) { foreach ($newJoinColumns as $name => $joinColumn) {
$changes['add'][$name] = $joinColumn; $changes['add'][$name] = $joinColumn;
} }
$sql[] = $this->_platform->getAlterTableSql($tableName, $changes); $sql[] = $this->_platform->getAlterTableSql($tableName, $changes);
} }
......
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