Fixed documentation for Doctrine\ORM\Tools\Export
This commit is contained in:
parent
0122d8d36c
commit
2524c878b6
@ -31,6 +31,9 @@ use Doctrine\ORM\Tools\Export\ExportException;
|
||||
*/
|
||||
class ClassMetadataExporter
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $_exporterDrivers = array(
|
||||
'xml' => 'Doctrine\ORM\Tools\Export\Driver\XmlExporter',
|
||||
'yaml' => 'Doctrine\ORM\Tools\Export\Driver\YamlExporter',
|
||||
@ -40,10 +43,12 @@ class ClassMetadataExporter
|
||||
);
|
||||
|
||||
/**
|
||||
* Register a new exporter driver class under a specified name
|
||||
* Registers a new exporter driver class under a specified name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function registerExportDriver($name, $class)
|
||||
{
|
||||
@ -51,12 +56,14 @@ class ClassMetadataExporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a exporter driver instance
|
||||
* Gets an exporter driver instance.
|
||||
*
|
||||
* @param string $type The type to get (yml, xml, etc.)
|
||||
* @param string $source The directory where the exporter will export to
|
||||
* @param string $type The type to get (yml, xml, etc.).
|
||||
* @param string|null $dest The directory where the exporter will export to.
|
||||
*
|
||||
* @return Driver\AbstractExporter $exporter
|
||||
* @return Driver\AbstractExporter
|
||||
*
|
||||
* @throws ExportException
|
||||
*/
|
||||
public function getExporter($type, $dest = null)
|
||||
{
|
||||
|
@ -24,8 +24,7 @@ use Doctrine\ORM\Tools\Export\ExportException;
|
||||
|
||||
/**
|
||||
* Abstract base class which is to be used for the Exporter drivers
|
||||
* which can be found in \Doctrine\ORM\Tools\Export\Driver
|
||||
*
|
||||
* which can be found in \Doctrine\ORM\Tools\Export\Driver.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
@ -33,16 +32,39 @@ use Doctrine\ORM\Tools\Export\ExportException;
|
||||
*/
|
||||
abstract class AbstractExporter
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_metadata = array();
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_outputDir;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $_extension;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_overwriteExistingFiles = false;
|
||||
|
||||
/**
|
||||
* @param string|null $dir
|
||||
*/
|
||||
public function __construct($dir = null)
|
||||
{
|
||||
$this->_outputDir = $dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $overwrite
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setOverwriteExistingFiles($overwrite)
|
||||
{
|
||||
$this->_overwriteExistingFiles = $overwrite;
|
||||
@ -50,17 +72,19 @@ abstract class AbstractExporter
|
||||
|
||||
/**
|
||||
* Converts a single ClassMetadata instance to the exported format
|
||||
* and returns it
|
||||
* and returns it.
|
||||
*
|
||||
* @param ClassMetadataInfo $metadata
|
||||
* @return mixed $exported
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function exportClassMetadata(ClassMetadataInfo $metadata);
|
||||
|
||||
/**
|
||||
* Set the array of ClassMetadataInfo instances to export
|
||||
* Sets the array of ClassMetadataInfo instances to export.
|
||||
*
|
||||
* @param array $metadata
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMetadata(array $metadata)
|
||||
@ -69,9 +93,9 @@ abstract class AbstractExporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extension used to generated the path to a class
|
||||
* Gets the extension used to generated the path to a class.
|
||||
*
|
||||
* @return string $extension
|
||||
* @return string|null
|
||||
*/
|
||||
public function getExtension()
|
||||
{
|
||||
@ -79,7 +103,7 @@ abstract class AbstractExporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directory to output the mapping files to
|
||||
* Sets the directory to output the mapping files to.
|
||||
*
|
||||
* [php]
|
||||
* $exporter = new YamlExporter($metadata);
|
||||
@ -87,6 +111,7 @@ abstract class AbstractExporter
|
||||
* $exporter->export();
|
||||
*
|
||||
* @param string $dir
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setOutputDir($dir)
|
||||
@ -95,10 +120,12 @@ abstract class AbstractExporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Export each ClassMetadata instance to a single Doctrine Mapping file
|
||||
* named after the entity
|
||||
* Exports each ClassMetadata instance to a single Doctrine Mapping file
|
||||
* named after the entity.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Doctrine\ORM\Tools\Export\ExportException
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
@ -123,10 +150,11 @@ abstract class AbstractExporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the path to write the class for the given ClassMetadataInfo instance
|
||||
* Generates the path to write the class for the given ClassMetadataInfo instance.
|
||||
*
|
||||
* @param ClassMetadataInfo $metadata
|
||||
* @return string $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _generateOutputPath(ClassMetadataInfo $metadata)
|
||||
{
|
||||
@ -134,7 +162,7 @@ abstract class AbstractExporter
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the directory to output the mapping files to
|
||||
* Sets the directory to output the mapping files to.
|
||||
*
|
||||
* [php]
|
||||
* $exporter = new YamlExporter($metadata, __DIR__ . '/yaml');
|
||||
@ -142,6 +170,7 @@ abstract class AbstractExporter
|
||||
* $exporter->export();
|
||||
*
|
||||
* @param string $extension
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setExtension($extension)
|
||||
@ -149,6 +178,11 @@ abstract class AbstractExporter
|
||||
$this->_extension = $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getInheritanceTypeString($type)
|
||||
{
|
||||
switch ($type) {
|
||||
@ -166,6 +200,11 @@ abstract class AbstractExporter
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $policy
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getChangeTrackingPolicyString($policy)
|
||||
{
|
||||
switch ($policy) {
|
||||
@ -180,6 +219,11 @@ abstract class AbstractExporter
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getIdGeneratorTypeString($type)
|
||||
{
|
||||
switch ($type) {
|
||||
|
@ -23,8 +23,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
use Doctrine\ORM\Tools\EntityGenerator;
|
||||
|
||||
/**
|
||||
* ClassMetadata exporter for PHP classes with annotations
|
||||
*
|
||||
* ClassMetadata exporter for PHP classes with annotations.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
@ -32,15 +31,18 @@ use Doctrine\ORM\Tools\EntityGenerator;
|
||||
*/
|
||||
class AnnotationExporter extends AbstractExporter
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_extension = '.php';
|
||||
|
||||
/**
|
||||
* @var EntityGenerator|null
|
||||
*/
|
||||
private $_entityGenerator;
|
||||
|
||||
/**
|
||||
* Converts a single ClassMetadata instance to the exported format
|
||||
* and returns it
|
||||
*
|
||||
* @param ClassMetadataInfo $metadata
|
||||
* @return string $exported
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exportClassMetadata(ClassMetadataInfo $metadata)
|
||||
{
|
||||
@ -56,11 +58,21 @@ class AnnotationExporter extends AbstractExporter
|
||||
return $this->_entityGenerator->generateEntityClass($metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _generateOutputPath(ClassMetadataInfo $metadata)
|
||||
{
|
||||
return $this->_outputDir . '/' . str_replace('\\', '/', $metadata->name) . $this->_extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\ORM\Tools\EntityGenerator $entityGenerator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setEntityGenerator(EntityGenerator $entityGenerator)
|
||||
{
|
||||
$this->_entityGenerator = $entityGenerator;
|
||||
|
@ -22,8 +22,7 @@ namespace Doctrine\ORM\Tools\Export\Driver;
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
|
||||
/**
|
||||
* ClassMetadata exporter for PHP code
|
||||
*
|
||||
* ClassMetadata exporter for PHP code.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
@ -31,14 +30,13 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
*/
|
||||
class PhpExporter extends AbstractExporter
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_extension = '.php';
|
||||
|
||||
/**
|
||||
* Converts a single ClassMetadata instance to the exported format
|
||||
* and returns it
|
||||
*
|
||||
* @param ClassMetadataInfo $metadata
|
||||
* @return mixed $exported
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exportClassMetadata(ClassMetadataInfo $metadata)
|
||||
{
|
||||
@ -154,6 +152,11 @@ class PhpExporter extends AbstractExporter
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $var
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _varExport($var)
|
||||
{
|
||||
$export = var_export($var, true);
|
||||
|
@ -22,7 +22,7 @@ namespace Doctrine\ORM\Tools\Export\Driver;
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
|
||||
/**
|
||||
* ClassMetadata exporter for Doctrine XML mapping files
|
||||
* ClassMetadata exporter for Doctrine XML mapping files.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
@ -30,14 +30,13 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
*/
|
||||
class XmlExporter extends AbstractExporter
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_extension = '.dcm.xml';
|
||||
|
||||
/**
|
||||
* Converts a single ClassMetadata instance to the exported format
|
||||
* and returns it
|
||||
*
|
||||
* @param ClassMetadataInfo $metadata
|
||||
* @return mixed $exported
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exportClassMetadata(ClassMetadataInfo $metadata)
|
||||
{
|
||||
|
@ -23,8 +23,7 @@ use Symfony\Component\Yaml\Yaml;
|
||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
|
||||
/**
|
||||
* ClassMetadata exporter for Doctrine YAML mapping files
|
||||
*
|
||||
* ClassMetadata exporter for Doctrine YAML mapping files.
|
||||
*
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
@ -32,16 +31,13 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||
*/
|
||||
class YamlExporter extends AbstractExporter
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_extension = '.dcm.yml';
|
||||
|
||||
/**
|
||||
* Converts a single ClassMetadata instance to the exported format
|
||||
* and returns it
|
||||
*
|
||||
* TODO: Should this code be pulled out in to a toArray() method in ClassMetadata
|
||||
*
|
||||
* @param ClassMetadataInfo $metadata
|
||||
* @return mixed $exported
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function exportClassMetadata(ClassMetadataInfo $metadata)
|
||||
{
|
||||
|
@ -6,16 +6,31 @@ use Doctrine\ORM\ORMException;
|
||||
|
||||
class ExportException extends ORMException
|
||||
{
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return ExportException
|
||||
*/
|
||||
public static function invalidExporterDriverType($type)
|
||||
{
|
||||
return new self("The specified export driver '$type' does not exist");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return ExportException
|
||||
*/
|
||||
public static function invalidMappingDriverType($type)
|
||||
{
|
||||
return new self("The mapping driver '$type' does not exist");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file
|
||||
*
|
||||
* @return ExportException
|
||||
*/
|
||||
public static function attemptOverwriteExistingFile($file)
|
||||
{
|
||||
return new self("Attempting to overwrite an existing file '".$file."'.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user