[2.0] Splitting ClassMetadata in to ClassMetadataInfo and other bug fixes
This commit is contained in:
parent
968ebb80c2
commit
d1b2f93acb
@ -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
|
|||||||
$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;
|
|||||||
*/
|
*/
|
||||||
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>.
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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
|
|||||||
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
|
|||||||
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
|
|||||||
$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) . ') '
|
||||||
|
1662
lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Normal file
1662
lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -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
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function loadMetadataForClass($className, ClassMetadata $metadata)
|
public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
|
||||||
{
|
{
|
||||||
$class = $metadata->getReflectionClass();
|
$class = $metadata->getReflectionClass();
|
||||||
|
|
||||||
|
@ -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
|
|||||||
* 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 @@
|
|||||||
|
|
||||||
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
|
|||||||
* @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
|
|||||||
// 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 @@
|
|||||||
|
|
||||||
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
|
|||||||
{
|
{
|
||||||
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
|
|||||||
// 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
|
|||||||
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 @@
|
|||||||
|
|
||||||
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
|
|||||||
$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
|
|||||||
$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
|
|||||||
}
|
}
|
||||||
|
|
||||||
$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');
|
||||||
|
@ -1,155 +0,0 @@
|
|||||||
<?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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|||||||
* 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
|
|||||||
{
|
{
|
||||||
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
|
|||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -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\AssociationMapping;
|
Doctrine\ORM\Mapping\AssociationMapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,26 +37,194 @@ use Doctrine\ORM\Mapping\ClassMetadata,
|
|||||||
class AnnotationExporter extends AbstractExporter
|
class AnnotationExporter extends AbstractExporter
|
||||||
{
|
{
|
||||||
protected $_extension = '.php';
|
protected $_extension = '.php';
|
||||||
|
protected $_isNew = false;
|
||||||
|
protected $_outputPath;
|
||||||
|
protected $_numSpaces = 4;
|
||||||
|
protected $_classToExtend;
|
||||||
|
protected $_currentCode;
|
||||||
|
|
||||||
|
public function hasProperty($property, $metadata)
|
||||||
|
{
|
||||||
|
if ($this->_isNew) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return strpos($this->_currentCode, '$' . $property) !== false ? true : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasMethod($method, $metadata)
|
||||||
|
{
|
||||||
|
if ($this->_isNew) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return strpos($this->_currentCode, 'function ' . $method) !== false ? true : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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)
|
||||||
{
|
{
|
||||||
|
if (file_exists($this->_outputPath)) {
|
||||||
|
$this->_currentCode = file_get_contents($this->_outputPath);
|
||||||
|
}
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
include('annotation.tpl.php');
|
include($this->_isNew ? 'annotation.tpl.php' : 'annotation_body.tpl.php');
|
||||||
$code = ob_get_contents();
|
$code = ob_get_contents();
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
|
||||||
$code = str_replace(array('[?php', '?]'), array('<?php', '?>'), $code);
|
$code = str_replace(array('[?php', '?]'), array('<?php', '?>'), $code);
|
||||||
|
$code = explode("\n", $code);
|
||||||
|
|
||||||
|
if ($this->_currentCode) {
|
||||||
|
$body = $code;
|
||||||
|
$code = $this->_currentCode;
|
||||||
|
$code = explode("\n", $code);
|
||||||
|
unset($code[array_search('}', $code)]);
|
||||||
|
foreach ($body as $line) {
|
||||||
|
$code[] = $line;
|
||||||
|
}
|
||||||
|
$code[] = '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
$code = array_values($code);
|
||||||
|
|
||||||
|
// Remove empty lines before last "}"
|
||||||
|
for ($i = count($code) - 1; $i > 0; --$i) {
|
||||||
|
$line = trim($code[$i]);
|
||||||
|
if ($line && $line != '}') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( ! $line) {
|
||||||
|
unset($code[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$code = array_values($code);
|
||||||
|
$code = implode("\n", $code);
|
||||||
|
|
||||||
return $code;
|
return $code;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _getTableAnnotation($metadata)
|
public function setNumSpaces($numSpaces)
|
||||||
|
{
|
||||||
|
$this->_numSpaces = $numSpaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function extendsClass()
|
||||||
|
{
|
||||||
|
return $this->_classToExtend ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClassToExtend()
|
||||||
|
{
|
||||||
|
return $this->_classToExtend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setClassToExtend($classToExtend)
|
||||||
|
{
|
||||||
|
$this->_classToExtend = $classToExtend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClassToExtendName()
|
||||||
|
{
|
||||||
|
$refl = new \ReflectionClass($this->getClassToExtend());
|
||||||
|
return $refl->getShortName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClassToExtendNamespace()
|
||||||
|
{
|
||||||
|
$refl = new \ReflectionClass($this->getClassToExtend());
|
||||||
|
return $refl->getNamespaceName() ? $refl->getNamespaceName():$refl->getShortName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getClassName($metadata)
|
||||||
|
{
|
||||||
|
return substr($metadata->name, strpos($metadata->name, '\\') + 1, strlen($metadata->name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNamespace($metadata)
|
||||||
|
{
|
||||||
|
return substr($metadata->name, 0, strrpos($metadata->name, '\\'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addMethod($type, $fieldName, $metadata, array &$methods)
|
||||||
|
{
|
||||||
|
$methodName = $type . ucfirst($fieldName);
|
||||||
|
if ($this->hasMethod($methodName, $metadata)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$method = array();
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . '/**';
|
||||||
|
if ($type == 'get') {
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . ' * Get ' . $fieldName;
|
||||||
|
} else if ($type == 'set') {
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . ' * Set ' . $fieldName;
|
||||||
|
} else if ($type == 'add') {
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . ' * Add ' . $fieldName;
|
||||||
|
}
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . ' */';
|
||||||
|
|
||||||
|
if ($type == 'get') {
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . 'public function ' . $methodName . '()';
|
||||||
|
} else if ($type == 'set') {
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . 'public function ' . $methodName . '($value)';
|
||||||
|
} else if ($type == 'add') {
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . 'public function ' . $methodName . '($value)';
|
||||||
|
}
|
||||||
|
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . '{';
|
||||||
|
if ($type == 'get') {
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . str_repeat(' ', $this->_numSpaces) . 'return $this->' . $fieldName . ';';
|
||||||
|
} else if ($type == 'set') {
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . str_repeat(' ', $this->_numSpaces) . '$this->' . $fieldName . ' = $value;';
|
||||||
|
} else if ($type == 'add') {
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . str_repeat(' ', $this->_numSpaces) . '$this->' . $fieldName . '[] = $value;';
|
||||||
|
}
|
||||||
|
|
||||||
|
$method[] = str_repeat(' ', $this->_numSpaces) . '}';
|
||||||
|
$method[] = "\n";
|
||||||
|
|
||||||
|
$methods[] = implode("\n", $method);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMethods($metadata)
|
||||||
|
{
|
||||||
|
$methods = array();
|
||||||
|
|
||||||
|
foreach ($metadata->fieldMappings as $fieldMapping) {
|
||||||
|
$this->addMethod('set', $fieldMapping['fieldName'], $metadata, $methods);
|
||||||
|
$this->addMethod('get', $fieldMapping['fieldName'], $metadata, $methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($metadata->associationMappings as $associationMapping) {
|
||||||
|
if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToOneMapping) {
|
||||||
|
$this->addMethod('set', $associationMapping->sourceFieldName, $metadata, $methods);
|
||||||
|
$this->addMethod('get', $associationMapping->sourceFieldName, $metadata, $methods);
|
||||||
|
} else if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToManyMapping) {
|
||||||
|
if ($associationMapping->isOwningSide) {
|
||||||
|
$this->addMethod('set', $associationMapping->sourceFieldName, $metadata, $methods);
|
||||||
|
$this->addMethod('get', $associationMapping->sourceFieldName, $metadata, $methods);
|
||||||
|
} else {
|
||||||
|
$this->addMethod('add', $associationMapping->sourceFieldName, $metadata, $methods);
|
||||||
|
$this->addMethod('get', $associationMapping->sourceFieldName, $metadata, $methods);
|
||||||
|
}
|
||||||
|
} else if ($associationMapping instanceof \Doctrine\ORM\Mapping\ManyToManyMapping) {
|
||||||
|
$this->addMethod('add', $associationMapping->sourceFieldName, $metadata, $methods);
|
||||||
|
$this->addMethod('get', $associationMapping->sourceFieldName, $metadata, $methods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $methods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTableAnnotation($metadata)
|
||||||
{
|
{
|
||||||
$table = array();
|
$table = array();
|
||||||
$table[] = 'name=' . $metadata->primaryTable['name'];
|
$table[] = 'name=' . $metadata->primaryTable['name'];
|
||||||
@ -66,21 +234,21 @@ class AnnotationExporter extends AbstractExporter
|
|||||||
return '@Table(' . implode(', ', $table) . ')';
|
return '@Table(' . implode(', ', $table) . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _getAssociationMappingAnnotation(AssociationMapping $associationMapping, ClassMetadata $metadata)
|
public function getAssociationMappingAnnotation(AssociationMapping $associationMapping, ClassMetadataInfo $metadata)
|
||||||
{
|
{
|
||||||
// TODO: This function still needs to be written :)
|
// TODO: This function still needs to be written :)
|
||||||
$lines = array();
|
$lines = array();
|
||||||
$lines[] = ' /**';
|
$lines[] = str_repeat(' ', $this->_numSpaces) . '/**';
|
||||||
$lines[] = ' *';
|
$lines[] = str_repeat(' ', $this->_numSpaces) . ' *';
|
||||||
$lines[] = ' */';
|
$lines[] = str_repeat(' ', $this->_numSpaces) . ' */';
|
||||||
|
|
||||||
return implode("\n", $lines);
|
return implode("\n", $lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _getFieldMappingAnnotation(array $fieldMapping, ClassMetadata $metadata)
|
public function getFieldMappingAnnotation(array $fieldMapping, ClassMetadataInfo $metadata)
|
||||||
{
|
{
|
||||||
$lines = array();
|
$lines = array();
|
||||||
$lines[] = ' /**';
|
$lines[] = str_repeat(' ', $this->_numSpaces) . '/**';
|
||||||
|
|
||||||
$column = array();
|
$column = array();
|
||||||
if (isset($fieldMapping['type'])) {
|
if (isset($fieldMapping['type'])) {
|
||||||
@ -110,11 +278,11 @@ class AnnotationExporter extends AbstractExporter
|
|||||||
if (isset($fieldMapping['unique'])) {
|
if (isset($fieldMapping['unique'])) {
|
||||||
$column[] = 'unique=' . var_export($fieldMapping['unique'], true);
|
$column[] = 'unique=' . var_export($fieldMapping['unique'], true);
|
||||||
}
|
}
|
||||||
$lines[] = ' * @Column(' . implode(', ', $column) . ')';
|
$lines[] = str_repeat(' ', $this->_numSpaces) . ' * @Column(' . implode(', ', $column) . ')';
|
||||||
if (isset($fieldMapping['id']) && $fieldMapping['id']) {
|
if (isset($fieldMapping['id']) && $fieldMapping['id']) {
|
||||||
$lines[] = ' * @Id';
|
$lines[] = str_repeat(' ', $this->_numSpaces) . ' * @Id';
|
||||||
if ($generatorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
|
if ($generatorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
|
||||||
$lines[] = ' * @GeneratedValue(strategy="' . $generatorType . '")';
|
$lines[] = str_repeat(' ', $this->_numSpaces).' * @GeneratedValue(strategy="' . $generatorType . '")';
|
||||||
}
|
}
|
||||||
if ($metadata->sequenceGeneratorDefinition) {
|
if ($metadata->sequenceGeneratorDefinition) {
|
||||||
$sequenceGenerator = array();
|
$sequenceGenerator = array();
|
||||||
@ -127,13 +295,13 @@ class AnnotationExporter extends AbstractExporter
|
|||||||
if (isset($metadata->sequenceGeneratorDefinition['initialValue'])) {
|
if (isset($metadata->sequenceGeneratorDefinition['initialValue'])) {
|
||||||
$sequenceGenerator[] = 'initialValue="' . $metadata->sequenceGeneratorDefinition['initialValue'] . '"';
|
$sequenceGenerator[] = 'initialValue="' . $metadata->sequenceGeneratorDefinition['initialValue'] . '"';
|
||||||
}
|
}
|
||||||
$lines[] = ' * @SequenceGenerator(' . implode(', ', $sequenceGenerator) . ')';
|
$lines[] = str_repeat(' ', $this->_numSpaces) . ' * @SequenceGenerator(' . implode(', ', $sequenceGenerator) . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($fieldMapping['version']) && $fieldMapping['version']) {
|
if (isset($fieldMapping['version']) && $fieldMapping['version']) {
|
||||||
$lines[] = ' * @Version';
|
$lines[] = str_repeat(' ', $this->_numSpaces) . ' * @Version';
|
||||||
}
|
}
|
||||||
$lines[] = ' */';
|
$lines[] = str_repeat(' ', $this->_numSpaces) . ' */';
|
||||||
|
|
||||||
return implode("\n", $lines);
|
return implode("\n", $lines);
|
||||||
}
|
}
|
||||||
@ -156,6 +324,10 @@ class AnnotationExporter extends AbstractExporter
|
|||||||
if ( ! is_dir($outputDir)) {
|
if ( ! is_dir($outputDir)) {
|
||||||
mkdir($outputDir, 0777, true);
|
mkdir($outputDir, 0777, true);
|
||||||
}
|
}
|
||||||
|
if ( ! file_exists($outputPath)) {
|
||||||
|
$this->_isNew = true;
|
||||||
|
}
|
||||||
|
$this->_outputPath = $outputPath;
|
||||||
$output = $this->exportClassMetadata($metadata);
|
$output = $this->exportClassMetadata($metadata);
|
||||||
file_put_contents($outputPath, $output);
|
file_put_contents($outputPath, $output);
|
||||||
}
|
}
|
||||||
|
@ -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 @@
|
|||||||
|
|
||||||
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
|
|||||||
* 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
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 @@
|
|||||||
|
|
||||||
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
|
|||||||
*
|
*
|
||||||
* 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
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
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
|
|||||||
|
|
||||||
$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
|
|||||||
|
|
||||||
$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,
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
[?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 ?>;
|
|||||||
<?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 include('annotation_body.tpl.php') ?>
|
||||||
<?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; ?>
|
|
||||||
|
|
||||||
}
|
}
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user