1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

Fixed documentation for Doctrine\ORM\Tools\Export

This commit is contained in:
Benjamin Morel 2012-12-14 13:02:12 +00:00
parent 0122d8d36c
commit 2524c878b6
7 changed files with 123 additions and 47 deletions

View file

@ -31,6 +31,9 @@ use Doctrine\ORM\Tools\Export\ExportException;
*/ */
class ClassMetadataExporter class ClassMetadataExporter
{ {
/**
* @var array
*/
private static $_exporterDrivers = array( private static $_exporterDrivers = array(
'xml' => 'Doctrine\ORM\Tools\Export\Driver\XmlExporter', 'xml' => 'Doctrine\ORM\Tools\Export\Driver\XmlExporter',
'yaml' => 'Doctrine\ORM\Tools\Export\Driver\YamlExporter', '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 $name
* @param string $class * @param string $class
*
* @return void
*/ */
public static function registerExportDriver($name, $class) 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 $type The type to get (yml, xml, etc.).
* @param string $source The directory where the exporter will export to * @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) public function getExporter($type, $dest = null)
{ {

View file

@ -24,8 +24,7 @@ use Doctrine\ORM\Tools\Export\ExportException;
/** /**
* Abstract base class which is to be used for the Exporter drivers * 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 * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
@ -33,16 +32,39 @@ use Doctrine\ORM\Tools\Export\ExportException;
*/ */
abstract class AbstractExporter abstract class AbstractExporter
{ {
/**
* @var array
*/
protected $_metadata = array(); protected $_metadata = array();
/**
* @var string|null
*/
protected $_outputDir; protected $_outputDir;
/**
* @var string|null
*/
protected $_extension; protected $_extension;
/**
* @var bool
*/
protected $_overwriteExistingFiles = false; protected $_overwriteExistingFiles = false;
/**
* @param string|null $dir
*/
public function __construct($dir = null) public function __construct($dir = null)
{ {
$this->_outputDir = $dir; $this->_outputDir = $dir;
} }
/**
* @param bool $overwrite
*
* @return void
*/
public function setOverwriteExistingFiles($overwrite) public function setOverwriteExistingFiles($overwrite)
{ {
$this->_overwriteExistingFiles = $overwrite; $this->_overwriteExistingFiles = $overwrite;
@ -50,17 +72,19 @@ 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 ClassMetadataInfo $metadata * @param ClassMetadataInfo $metadata
* @return mixed $exported *
* @return string
*/ */
abstract public function exportClassMetadata(ClassMetadataInfo $metadata); 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 * @param array $metadata
*
* @return void * @return void
*/ */
public function setMetadata(array $metadata) 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() 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] * [php]
* $exporter = new YamlExporter($metadata); * $exporter = new YamlExporter($metadata);
@ -87,6 +111,7 @@ abstract class AbstractExporter
* $exporter->export(); * $exporter->export();
* *
* @param string $dir * @param string $dir
*
* @return void * @return void
*/ */
public function setOutputDir($dir) public function setOutputDir($dir)
@ -95,10 +120,12 @@ abstract class AbstractExporter
} }
/** /**
* Export each ClassMetadata instance to a single Doctrine Mapping file * Exports each ClassMetadata instance to a single Doctrine Mapping file
* named after the entity * named after the entity.
* *
* @return void * @return void
*
* @throws \Doctrine\ORM\Tools\Export\ExportException
*/ */
public function export() 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 * @param ClassMetadataInfo $metadata
* @return string $path *
* @return string
*/ */
protected function _generateOutputPath(ClassMetadataInfo $metadata) 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] * [php]
* $exporter = new YamlExporter($metadata, __DIR__ . '/yaml'); * $exporter = new YamlExporter($metadata, __DIR__ . '/yaml');
@ -142,6 +170,7 @@ abstract class AbstractExporter
* $exporter->export(); * $exporter->export();
* *
* @param string $extension * @param string $extension
*
* @return void * @return void
*/ */
public function setExtension($extension) public function setExtension($extension)
@ -149,6 +178,11 @@ abstract class AbstractExporter
$this->_extension = $extension; $this->_extension = $extension;
} }
/**
* @param int $type
*
* @return string
*/
protected function _getInheritanceTypeString($type) protected function _getInheritanceTypeString($type)
{ {
switch ($type) { switch ($type) {
@ -166,6 +200,11 @@ abstract class AbstractExporter
} }
} }
/**
* @param int $policy
*
* @return string
*/
protected function _getChangeTrackingPolicyString($policy) protected function _getChangeTrackingPolicyString($policy)
{ {
switch ($policy) { switch ($policy) {
@ -180,6 +219,11 @@ abstract class AbstractExporter
} }
} }
/**
* @param int $type
*
* @return string
*/
protected function _getIdGeneratorTypeString($type) protected function _getIdGeneratorTypeString($type)
{ {
switch ($type) { switch ($type) {

View file

@ -23,8 +23,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Tools\EntityGenerator; use Doctrine\ORM\Tools\EntityGenerator;
/** /**
* ClassMetadata exporter for PHP classes with annotations * ClassMetadata exporter for PHP classes with annotations.
*
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
@ -32,15 +31,18 @@ use Doctrine\ORM\Tools\EntityGenerator;
*/ */
class AnnotationExporter extends AbstractExporter class AnnotationExporter extends AbstractExporter
{ {
/**
* @var string
*/
protected $_extension = '.php'; protected $_extension = '.php';
/**
* @var EntityGenerator|null
*/
private $_entityGenerator; private $_entityGenerator;
/** /**
* Converts a single ClassMetadata instance to the exported format * {@inheritdoc}
* and returns it
*
* @param ClassMetadataInfo $metadata
* @return string $exported
*/ */
public function exportClassMetadata(ClassMetadataInfo $metadata) public function exportClassMetadata(ClassMetadataInfo $metadata)
{ {
@ -56,11 +58,21 @@ class AnnotationExporter extends AbstractExporter
return $this->_entityGenerator->generateEntityClass($metadata); return $this->_entityGenerator->generateEntityClass($metadata);
} }
/**
* @param \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata
*
* @return string
*/
protected function _generateOutputPath(ClassMetadataInfo $metadata) protected function _generateOutputPath(ClassMetadataInfo $metadata)
{ {
return $this->_outputDir . '/' . str_replace('\\', '/', $metadata->name) . $this->_extension; return $this->_outputDir . '/' . str_replace('\\', '/', $metadata->name) . $this->_extension;
} }
/**
* @param \Doctrine\ORM\Tools\EntityGenerator $entityGenerator
*
* @return void
*/
public function setEntityGenerator(EntityGenerator $entityGenerator) public function setEntityGenerator(EntityGenerator $entityGenerator)
{ {
$this->_entityGenerator = $entityGenerator; $this->_entityGenerator = $entityGenerator;

View file

@ -22,8 +22,7 @@ namespace Doctrine\ORM\Tools\Export\Driver;
use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\ClassMetadataInfo;
/** /**
* ClassMetadata exporter for PHP code * ClassMetadata exporter for PHP code.
*
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
@ -31,14 +30,13 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
*/ */
class PhpExporter extends AbstractExporter class PhpExporter extends AbstractExporter
{ {
/**
* @var string
*/
protected $_extension = '.php'; protected $_extension = '.php';
/** /**
* Converts a single ClassMetadata instance to the exported format * {@inheritdoc}
* and returns it
*
* @param ClassMetadataInfo $metadata
* @return mixed $exported
*/ */
public function exportClassMetadata(ClassMetadataInfo $metadata) public function exportClassMetadata(ClassMetadataInfo $metadata)
{ {
@ -154,6 +152,11 @@ class PhpExporter extends AbstractExporter
return implode("\n", $lines); return implode("\n", $lines);
} }
/**
* @param mixed $var
*
* @return string
*/
protected function _varExport($var) protected function _varExport($var)
{ {
$export = var_export($var, true); $export = var_export($var, true);

View file

@ -22,7 +22,7 @@ namespace Doctrine\ORM\Tools\Export\Driver;
use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\ClassMetadataInfo;
/** /**
* ClassMetadata exporter for Doctrine XML mapping files * ClassMetadata exporter for Doctrine XML mapping files.
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
@ -30,14 +30,13 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
*/ */
class XmlExporter extends AbstractExporter class XmlExporter extends AbstractExporter
{ {
/**
* @var string
*/
protected $_extension = '.dcm.xml'; protected $_extension = '.dcm.xml';
/** /**
* Converts a single ClassMetadata instance to the exported format * {@inheritdoc}
* and returns it
*
* @param ClassMetadataInfo $metadata
* @return mixed $exported
*/ */
public function exportClassMetadata(ClassMetadataInfo $metadata) public function exportClassMetadata(ClassMetadataInfo $metadata)
{ {

View file

@ -23,8 +23,7 @@ use Symfony\Component\Yaml\Yaml;
use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\ClassMetadataInfo;
/** /**
* ClassMetadata exporter for Doctrine YAML mapping files * ClassMetadata exporter for Doctrine YAML mapping files.
*
* *
* @link www.doctrine-project.org * @link www.doctrine-project.org
* @since 2.0 * @since 2.0
@ -32,16 +31,13 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo;
*/ */
class YamlExporter extends AbstractExporter class YamlExporter extends AbstractExporter
{ {
/**
* @var string
*/
protected $_extension = '.dcm.yml'; protected $_extension = '.dcm.yml';
/** /**
* Converts a single ClassMetadata instance to the exported format * {@inheritdoc}
* and returns it
*
* TODO: Should this code be pulled out in to a toArray() method in ClassMetadata
*
* @param ClassMetadataInfo $metadata
* @return mixed $exported
*/ */
public function exportClassMetadata(ClassMetadataInfo $metadata) public function exportClassMetadata(ClassMetadataInfo $metadata)
{ {

View file

@ -6,16 +6,31 @@ use Doctrine\ORM\ORMException;
class ExportException extends ORMException class ExportException extends ORMException
{ {
/**
* @param string $type
*
* @return ExportException
*/
public static function invalidExporterDriverType($type) public static function invalidExporterDriverType($type)
{ {
return new self("The specified export driver '$type' does not exist"); return new self("The specified export driver '$type' does not exist");
} }
/**
* @param string $type
*
* @return ExportException
*/
public static function invalidMappingDriverType($type) public static function invalidMappingDriverType($type)
{ {
return new self("The mapping driver '$type' does not exist"); return new self("The mapping driver '$type' does not exist");
} }
/**
* @param string $file
*
* @return ExportException
*/
public static function attemptOverwriteExistingFile($file) public static function attemptOverwriteExistingFile($file)
{ {
return new self("Attempting to overwrite an existing file '".$file."'."); return new self("Attempting to overwrite an existing file '".$file."'.");