1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Fixed documentation for Doctrine\ORM\Tools

This commit is contained in:
Benjamin Morel 2012-12-13 18:55:44 +00:00
parent 7869ec714d
commit e72445b836
10 changed files with 435 additions and 108 deletions

View File

@ -36,7 +36,14 @@ use Symfony\Component\Yaml\Yaml;
*/
class ConvertDoctrine1Schema
{
/**
* @var array
*/
private $from;
/**
* @var array
*/
private $legacyTypeMap = array(
// TODO: This list may need to be updated
'clob' => 'text',
@ -46,9 +53,10 @@ class ConvertDoctrine1Schema
/**
* Constructor passes the directory or array of directories
* to convert the Doctrine 1 schema files from
* to convert the Doctrine 1 schema files from.
*
* @param array $from
*
* @author Jonathan Wage
*/
public function __construct($from)
@ -57,10 +65,10 @@ class ConvertDoctrine1Schema
}
/**
* Get an array of ClassMetadataInfo instances from the passed
* Doctrine 1 schema
* Gets an array of ClassMetadataInfo instances from the passed
* Doctrine 1 schema.
*
* @return array $metadatas An array of ClassMetadataInfo instances
* @return array An array of ClassMetadataInfo instances
*/
public function getMetadata()
{
@ -84,6 +92,12 @@ class ConvertDoctrine1Schema
return $metadatas;
}
/**
* @param string $className
* @param array $mappingInformation
*
* @return \Doctrine\ORM\Mapping\ClassMetadataInfo
*/
private function convertToClassMetadataInfo($className, $mappingInformation)
{
$metadata = new ClassMetadataInfo($className);
@ -96,6 +110,13 @@ class ConvertDoctrine1Schema
return $metadata;
}
/**
* @param string $className
* @param array $model
* @param ClassMetadataInfo $metadata
*
* @return void
*/
private function convertTableName($className, array $model, ClassMetadataInfo $metadata)
{
if (isset($model['tableName']) && $model['tableName']) {
@ -110,6 +131,13 @@ class ConvertDoctrine1Schema
}
}
/**
* @param string $className
* @param array $model
* @param ClassMetadataInfo $metadata
*
* @return void
*/
private function convertColumns($className, array $model, ClassMetadataInfo $metadata)
{
$id = false;
@ -136,6 +164,16 @@ class ConvertDoctrine1Schema
}
}
/**
* @param string $className
* @param string $name
* @param string|array $column
* @param ClassMetadataInfo $metadata
*
* @return array
*
* @throws ToolsException
*/
private function convertColumn($className, $name, $column, ClassMetadataInfo $metadata)
{
if (is_string($column)) {
@ -217,6 +255,13 @@ class ConvertDoctrine1Schema
return $fieldMapping;
}
/**
* @param string $className
* @param array $model
* @param ClassMetadataInfo $metadata
*
* @return void
*/
private function convertIndexes($className, array $model, ClassMetadataInfo $metadata)
{
if (empty($model['indexes'])) {
@ -233,6 +278,13 @@ class ConvertDoctrine1Schema
}
}
/**
* @param string $className
* @param array $model
* @param ClassMetadataInfo $metadata
*
* @return void
*/
private function convertRelations($className, array $model, ClassMetadataInfo $metadata)
{
if (empty($model['relations'])) {

View File

@ -32,11 +32,18 @@ use Doctrine\ORM\EntityManager;
*/
class DebugUnitOfWorkListener
{
/**
* @var string
*/
private $file;
/**
* @var string
*/
private $context;
/**
* Pass a stream and contet information for the debugging session.
* Pass a stream and context information for the debugging session.
*
* The stream can be php://output to print to the screen.
*
@ -49,15 +56,21 @@ class DebugUnitOfWorkListener
$this->context = $context;
}
/**
* @param \Doctrine\ORM\Event\OnFlushEventArgs $args
*
* @return void
*/
public function onFlush(OnFlushEventArgs $args)
{
$this->dumpIdentityMap($args->getEntityManager());
}
/**
* Dump the contents of the identity map into a stream.
* Dumps the contents of the identity map into a stream.
*
* @param EntityManager $em
*
* @return void
*/
public function dumpIdentityMap(EntityManager $em)
@ -119,6 +132,11 @@ class DebugUnitOfWorkListener
fclose($fh);
}
/**
* @param mixed $var
*
* @return string
*/
private function getType($var)
{
if (is_object($var)) {
@ -130,6 +148,12 @@ class DebugUnitOfWorkListener
return gettype($var);
}
/**
* @param object $entity
* @param UnitOfWork $uow
*
* @return string
*/
private function getIdString($entity, UnitOfWork $uow)
{
if ($uow->isInIdentityMap($entity)) {

View File

@ -38,6 +38,9 @@ use Doctrine\ORM\Mapping\ClassMetadataFactory;
*/
class DisconnectedClassMetadataFactory extends ClassMetadataFactory
{
/**
* @return \Doctrine\Common\Persistence\Mapping\StaticReflectionService
*/
public function getReflectionService()
{
return new StaticReflectionService();

View File

@ -24,7 +24,7 @@ use Doctrine\Common\Util\Inflector;
use Doctrine\DBAL\Types\Type;
/**
* Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances
* Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances.
*
* [php]
* $classes = $em->getClassMetadataFactory()->getAllMetadata();
@ -47,12 +47,12 @@ use Doctrine\DBAL\Types\Type;
class EntityGenerator
{
/**
* Specifies class fields should be protected
* Specifies class fields should be protected.
*/
const FIELD_VISIBLE_PROTECTED = 'protected';
/**
* Specifies class fields should be private
* Specifies class fields should be private.
*/
const FIELD_VISIBLE_PRIVATE = 'private';
@ -62,14 +62,14 @@ class EntityGenerator
protected $backupExisting = true;
/**
* The extension to use for written php files
* The extension to use for written php files.
*
* @var string
*/
protected $extension = '.php';
/**
* Whether or not the current ClassMetadataInfo instance is new or old
* Whether or not the current ClassMetadataInfo instance is new or old.
*
* @var boolean
*/
@ -81,26 +81,26 @@ class EntityGenerator
protected $staticReflection = array();
/**
* Number of spaces to use for indention in generated code
* Number of spaces to use for indention in generated code.
*/
protected $numSpaces = 4;
/**
* The actual spaces to use for indention
* The actual spaces to use for indention.
*
* @var string
*/
protected $spaces = ' ';
/**
* The class all generated entities should extend
* The class all generated entities should extend.
*
* @var string
*/
protected $classToExtend;
/**
* Whether or not to generation annotations
* Whether or not to generation annotations.
*
* @var boolean
*/
@ -112,21 +112,21 @@ class EntityGenerator
protected $annotationsPrefix = '';
/**
* Whether or not to generated sub methods
* Whether or not to generate sub methods.
*
* @var boolean
*/
protected $generateEntityStubMethods = false;
/**
* Whether or not to update the entity class if it exists already
* Whether or not to update the entity class if it exists already.
*
* @var boolean
*/
protected $updateEntityIfExists = false;
/**
* Whether or not to re-generate entity class if it exists already
* Whether or not to re-generate entity class if it exists already.
*
* @var boolean
*/
@ -138,7 +138,7 @@ class EntityGenerator
protected $fieldVisibility = 'private';
/**
* Hash-map for handle types
* Hash-map for handle types.
*
* @var array
*/
@ -158,7 +158,9 @@ class EntityGenerator
);
/**
* @var array Hash-map to handle generator types string.
* Hash-map to handle generator types string.
*
* @var array
*/
protected static $generatorStrategyMap = array(
ClassMetadataInfo::GENERATOR_TYPE_AUTO => 'AUTO',
@ -171,7 +173,9 @@ class EntityGenerator
);
/**
* @var array Hash-map to handle the change tracking policy string.
* Hash-map to handle the change tracking policy string.
*
* @var array
*/
protected static $changeTrackingPolicyMap = array(
ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT => 'DEFERRED_IMPLICIT',
@ -180,7 +184,9 @@ class EntityGenerator
);
/**
* @var array Hash-map to handle the inheritance type string.
* Hash-map to handle the inheritance type string.
*
* @var array
*/
protected static $inheritanceTypeMap = array(
ClassMetadataInfo::INHERITANCE_TYPE_NONE => 'NONE',
@ -301,10 +307,11 @@ public function __construct()
}
/**
* Generate and write entity classes for the given array of ClassMetadataInfo instances
* Generates and writes entity classes for the given array of ClassMetadataInfo instances.
*
* @param array $metadatas
* @param array $metadatas
* @param string $outputDirectory
*
* @return void
*/
public function generate(array $metadatas, $outputDirectory)
@ -315,11 +322,14 @@ public function __construct()
}
/**
* Generated and write entity class to disk for the given ClassMetadataInfo instance
* Generates and writes entity class to disk for the given ClassMetadataInfo instance.
*
* @param ClassMetadataInfo $metadata
* @param string $outputDirectory
* @param string $outputDirectory
*
* @return void
*
* @throws \RuntimeException
*/
public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory)
{
@ -355,10 +365,11 @@ public function __construct()
}
/**
* Generate a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance
* Generates a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance.
*
* @param ClassMetadataInfo $metadata
* @return string $code
*
* @return string
*/
public function generateEntityClass(ClassMetadataInfo $metadata)
{
@ -382,11 +393,12 @@ public function __construct()
}
/**
* Generate the updated code for the given ClassMetadataInfo and entity at path
* Generates the updated code for the given ClassMetadataInfo and entity at path.
*
* @param ClassMetadataInfo $metadata
* @param string $path
* @return string $code;
* @param string $path
*
* @return string
*/
public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path)
{
@ -400,9 +412,10 @@ public function __construct()
}
/**
* Set the number of spaces the exported class should have
* Sets the number of spaces the exported class should have.
*
* @param integer $numSpaces
*
* @return void
*/
public function setNumSpaces($numSpaces)
@ -412,9 +425,10 @@ public function __construct()
}
/**
* Set the extension to use when writing php files to disk
* Sets the extension to use when writing php files to disk.
*
* @param string $extension
*
* @return void
*/
public function setExtension($extension)
@ -423,7 +437,7 @@ public function __construct()
}
/**
* Set the name of the class the generated classes should extend from
* Sets the name of the class the generated classes should extend from.
*
* @return void
*/
@ -433,9 +447,10 @@ public function __construct()
}
/**
* Set whether or not to generate annotations for the entity
* Sets whether or not to generate annotations for the entity.
*
* @param bool $bool
*
* @return void
*/
public function setGenerateAnnotations($bool)
@ -444,10 +459,13 @@ public function __construct()
}
/**
* Set the class fields visibility for the entity (can either be private or protected)
* Sets the class fields visibility for the entity (can either be private or protected).
*
* @param bool $visibility
*
* @param bool $bool
* @return void
*
* @throws \InvalidArgumentException
*/
public function setFieldVisibility($visibility)
{
@ -459,9 +477,11 @@ public function __construct()
}
/**
* Set an annotation prefix.
* Sets an annotation prefix.
*
* @param string $prefix
*
* @return void
*/
public function setAnnotationPrefix($prefix)
{
@ -469,9 +489,10 @@ public function __construct()
}
/**
* Set whether or not to try and update the entity if it already exists
* Sets whether or not to try and update the entity if it already exists.
*
* @param bool $bool
*
* @return void
*/
public function setUpdateEntityIfExists($bool)
@ -480,9 +501,10 @@ public function __construct()
}
/**
* Set whether or not to regenerate the entity if it exists
* Sets whether or not to regenerate the entity if it exists.
*
* @param bool $bool
*
* @return void
*/
public function setRegenerateEntityIfExists($bool)
@ -491,9 +513,10 @@ public function __construct()
}
/**
* Set whether or not to generate stub methods for the entity
* Sets whether or not to generate stub methods for the entity.
*
* @param bool $bool
*
* @return void
*/
public function setGenerateStubMethods($bool)
@ -503,15 +526,20 @@ public function __construct()
/**
* Should an existing entity be backed up if it already exists?
*
* @param bool $bool
*
* @return void
*/
public function setBackupExisting($bool)
{
$this->backupExisting = $bool;
}
/**
* @param string $type
* @return string
/**
* @param string $type
*
* @return string
*/
protected function getType($type)
{
@ -522,6 +550,11 @@ public function __construct()
return $type;
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateEntityNamespace(ClassMetadataInfo $metadata)
{
if ($this->hasNamespace($metadata)) {
@ -529,12 +562,22 @@ public function __construct()
}
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateEntityClassName(ClassMetadataInfo $metadata)
{
return 'class ' . $this->getClassName($metadata) .
($this->extendsClass() ? ' extends ' . $this->getClassToExtendName() : null);
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateEntityBody(ClassMetadataInfo $metadata)
{
$fieldMappingProperties = $this->generateEntityFieldMappingProperties($metadata);
@ -565,6 +608,11 @@ public function __construct()
return implode("\n", $code);
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateEntityConstructor(ClassMetadataInfo $metadata)
{
if ($this->hasMethod('__construct', $metadata)) {
@ -588,7 +636,10 @@ public function __construct()
/**
* @todo this won't work if there is a namespace in brackets and a class outside of it.
*
* @param string $src
*
* @return void
*/
protected function parseTokensInEntityFile($src)
{
@ -637,6 +688,12 @@ public function __construct()
}
}
/**
* @param string $property
* @param ClassMetadataInfo $metadata
*
* @return bool
*/
protected function hasProperty($property, ClassMetadataInfo $metadata)
{
if ($this->extendsClass()) {
@ -653,6 +710,12 @@ public function __construct()
);
}
/**
* @param string $method
* @param ClassMetadataInfo $metadata
*
* @return bool
*/
protected function hasMethod($method, ClassMetadataInfo $metadata)
{
if ($this->extendsClass()) {
@ -670,21 +733,35 @@ public function __construct()
);
}
/**
* @param ClassMetadataInfo $metadata
*
* @return bool
*/
protected function hasNamespace(ClassMetadataInfo $metadata)
{
return strpos($metadata->name, '\\') ? true : false;
}
/**
* @return bool
*/
protected function extendsClass()
{
return $this->classToExtend ? true : false;
}
/**
* @return string
*/
protected function getClassToExtend()
{
return $this->classToExtend;
}
/**
* @return string
*/
protected function getClassToExtendName()
{
$refl = new \ReflectionClass($this->getClassToExtend());
@ -692,17 +769,32 @@ public function __construct()
return '\\' . $refl->getName();
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function getClassName(ClassMetadataInfo $metadata)
{
return ($pos = strrpos($metadata->name, '\\'))
? substr($metadata->name, $pos + 1, strlen($metadata->name)) : $metadata->name;
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function getNamespace(ClassMetadataInfo $metadata)
{
return substr($metadata->name, 0, strrpos($metadata->name, '\\'));
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateEntityDocBlock(ClassMetadataInfo $metadata)
{
$lines = array();
@ -745,6 +837,11 @@ public function __construct()
return implode("\n", $lines);
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateTableAnnotation($metadata)
{
$table = array();
@ -770,6 +867,12 @@ public function __construct()
return '@' . $this->annotationsPrefix . 'Table(' . implode(', ', $table) . ')';
}
/**
* @param string $constraintName
* @param array $constraints
*
* @return string
*/
protected function generateTableConstraints($constraintName, $constraints)
{
$annotations = array();
@ -783,6 +886,11 @@ public function __construct()
return implode(', ', $annotations);
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateInheritanceAnnotation($metadata)
{
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
@ -790,6 +898,11 @@ public function __construct()
}
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateDiscriminatorColumnAnnotation($metadata)
{
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
@ -802,6 +915,11 @@ public function __construct()
}
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateDiscriminatorMapAnnotation($metadata)
{
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
@ -815,6 +933,11 @@ public function __construct()
}
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateEntityStubMethods(ClassMetadataInfo $metadata)
{
$methods = array();
@ -856,6 +979,11 @@ public function __construct()
return implode("\n\n", $methods);
}
/**
* @param array $associationMapping
*
* @return bool
*/
protected function isAssociationIsNullable($associationMapping)
{
if (isset($associationMapping['id']) && $associationMapping['id']) {
@ -878,6 +1006,11 @@ public function __construct()
return true;
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata)
{
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
@ -897,6 +1030,11 @@ public function __construct()
return "";
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata)
{
$lines = array();
@ -914,6 +1052,11 @@ public function __construct()
return implode("\n", $lines);
}
/**
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateEntityFieldMappingProperties(ClassMetadataInfo $metadata)
{
$lines = array();
@ -932,6 +1075,15 @@ public function __construct()
return implode("\n", $lines);
}
/**
* @param ClassMetadataInfo $metadata
* @param string $type
* @param string $fieldName
* @param string|null $typeHint
* @param string|null $defaultValue
*
* @return string
*/
protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
{
$methodName = $type . Inflector::classify($fieldName);
@ -976,6 +1128,13 @@ public function __construct()
return $this->prefixCodeWithSpaces($method);
}
/**
* @param string $name
* @param string $methodName
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateLifecycleCallbackMethod($name, $methodName, $metadata)
{
if ($this->hasMethod($methodName, $metadata)) {
@ -997,6 +1156,11 @@ public function __construct()
return $this->prefixCodeWithSpaces($method);
}
/**
* @param array $joinColumn
*
* @return string
*/
protected function generateJoinColumnAnnotation(array $joinColumn)
{
$joinColumnAnnot = array();
@ -1028,6 +1192,12 @@ public function __construct()
return '@' . $this->annotationsPrefix . 'JoinColumn(' . implode(', ', $joinColumnAnnot) . ')';
}
/**
* @param array $associationMapping
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateAssociationMappingPropertyDocBlock(array $associationMapping, ClassMetadataInfo $metadata)
{
$lines = array();
@ -1165,6 +1335,12 @@ public function __construct()
return implode("\n", $lines);
}
/**
* @param array $fieldMapping
* @param ClassMetadataInfo $metadata
*
* @return string
*/
protected function generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata)
{
$lines = array();
@ -1245,6 +1421,12 @@ public function __construct()
return implode("\n", $lines);
}
/**
* @param string $code
* @param int $num
*
* @return string
*/
protected function prefixCodeWithSpaces($code, $num = 1)
{
$lines = explode("\n", $code);
@ -1259,9 +1441,11 @@ public function __construct()
}
/**
* @param integer $type The inheritance type used by the class and its subclasses.
* @return string The literal string for the inheritance type.
* @throws \InvalidArgumentException When the inheritance type does not exists.
* @param integer $type The inheritance type used by the class and its subclasses.
*
* @return string The literal string for the inheritance type.
*
* @throws \InvalidArgumentException When the inheritance type does not exists.
*/
protected function getInheritanceTypeString($type)
{
@ -1273,9 +1457,11 @@ public function __construct()
}
/**
* @param integer $type The policy used for change-tracking for the mapped class.
* @return string The literal string for the change-tracking type.
* @throws \InvalidArgumentException When the change-tracking type does not exists.
* @param integer $type The policy used for change-tracking for the mapped class.
*
* @return string The literal string for the change-tracking type.
*
* @throws \InvalidArgumentException When the change-tracking type does not exists.
*/
protected function getChangeTrackingPolicyString($type)
{
@ -1287,8 +1473,10 @@ public function __construct()
}
/**
* @param integer $type The generator to use for the mapped class.
* @return string The literal string for the generetor type.
* @param integer $type The generator to use for the mapped class.
*
* @return string The literal string for the generetor type.
*
* @throws \InvalidArgumentException When the generator type does not exists.
*/
protected function getIdGeneratorTypeString($type)

View File

@ -50,6 +50,11 @@ class <className> extends EntityRepository
}
';
/**
* @param string $fullClassName
*
* @return string
*/
public function generateEntityRepositoryClass($fullClassName)
{
$className = substr($fullClassName, strrpos($fullClassName, '\\') + 1, strlen($fullClassName));
@ -63,9 +68,10 @@ class <className> extends EntityRepository
}
/**
* Generate the namespace statement, if class do not have namespace, return empty string instead
* Generates the namespace statement, if class do not have namespace, return empty string instead.
*
* @param string $fullClassName The full repository class name
* @param string $fullClassName The full repository class name.
*
* @return string $namespace
*/
private function generateEntityRepositoryNamespace($fullClassName)
@ -74,7 +80,13 @@ class <className> extends EntityRepository
return $namespace ? 'namespace ' . $namespace . ';' : '';
}
/**
* @param string $fullClassName
* @param string $outputDirectory
*
* @return void
*/
public function writeEntityRepositoryClass($fullClassName, $outputDirectory)
{
$code = $this->generateEntityRepositoryClass($fullClassName);

View File

@ -39,11 +39,12 @@ class ResolveTargetEntityListener
private $resolveTargetEntities = array();
/**
* Add a target-entity class name to resolve to a new class name.
* Adds a target-entity class name to resolve to a new class name.
*
* @param string $originalEntity
* @param string $newEntity
* @param array $mapping
* @param array $mapping
*
* @return void
*/
public function addResolveTargetEntity($originalEntity, $newEntity, array $mapping)
@ -53,9 +54,10 @@ class ResolveTargetEntityListener
}
/**
* Process event and resolve new target entity names.
* Processes event and resolves new target entity names.
*
* @param LoadClassMetadataEventArgs $args
*
* @return void
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $args)
@ -69,6 +71,12 @@ class ResolveTargetEntityListener
}
}
/**
* @param \Doctrine\ORM\Mapping\ClassMetadataInfo $classMetadata
* @param array $mapping
*
* @return void
*/
private function remapAssociation($classMetadata, $mapping)
{
$newMapping = $this->resolveTargetEntities[$mapping['targetEntity']];
@ -93,4 +101,3 @@ class ResolveTargetEntityListener
}
}
}

View File

@ -79,9 +79,11 @@ class SchemaTool
/**
* Creates the database schema for the given array of ClassMetadata instances.
*
* @throws ToolsException
* @param array $classes
*
* @return void
*
* @throws ToolsException
*/
public function createSchema(array $classes)
{
@ -102,7 +104,8 @@ class SchemaTool
* the given list of ClassMetadata instances.
*
* @param array $classes
* @return array $sql The SQL statements needed to create the schema for the classes.
*
* @return array The SQL statements needed to create the schema for the classes.
*/
public function getCreateSchemaSql(array $classes)
{
@ -111,10 +114,11 @@ class SchemaTool
}
/**
* Some instances of ClassMetadata don't need to be processed in the SchemaTool context. This method detects them.
* Detects instances of ClassMetadata that don't need to be processed in the SchemaTool context.
*
* @param ClassMetadata $class
* @param array $processedClasses
* @param array $processedClasses
*
* @return bool
*/
private function processingNotRequired($class, array $processedClasses)
@ -127,10 +131,13 @@ class SchemaTool
}
/**
* From a given set of metadata classes this method creates a Schema instance.
* Creates a Schema instance from a given set of metadata classes.
*
* @param array $classes
*
* @return Schema
*
* @throws \Doctrine\ORM\ORMException
*/
public function getSchemaFromMetadata(array $classes)
{
@ -288,9 +295,10 @@ class SchemaTool
* column of a class.
*
* @param ClassMetadata $class
* @param Table $table
* @param Table $table
*
* @return array The portable column definition of the discriminator column as required by
* the DBAL.
* the DBAL.
*/
private function addDiscriminatorColumnDefinition($class, Table $table)
{
@ -318,7 +326,8 @@ class SchemaTool
* found in the given class.
*
* @param ClassMetadata $class
* @param Table $table
* @param Table $table
*
* @return array The list of portable column definitions as required by the DBAL.
*/
private function gatherColumns($class, Table $table)
@ -347,9 +356,10 @@ class SchemaTool
/**
* Creates a column definition as required by the DBAL from an ORM field mapping definition.
*
* @param ClassMetadata $class The class that owns the field mapping.
* @param array $mapping The field mapping.
* @param Table $table
* @param ClassMetadata $class The class that owns the field mapping.
* @param array $mapping The field mapping.
* @param Table $table
*
* @return array The portable column definition as required by the DBAL.
*/
private function gatherColumn($class, array $mapping, Table $table)
@ -434,11 +444,14 @@ class SchemaTool
* This includes the SQL for foreign key constraints and join tables.
*
* @param ClassMetadata $class
* @param \Doctrine\DBAL\Schema\Table $table
* @param \Doctrine\DBAL\Schema\Schema $schema
* @param array $addedFks
* @param array $blacklistedFks
* @param Table $table
* @param Schema $schema
* @param array $addedFks
* @param array $blacklistedFks
*
* @return void
*
* @throws \Doctrine\ORM\ORMException
*/
private function gatherRelationsSql($class, $table, $schema, &$addedFks, &$blacklistedFks)
{
@ -484,7 +497,7 @@ class SchemaTool
}
/**
* Get the class metadata that is responsible for the definition of the referenced column name.
* Gets the class metadata that is responsible for the definition of the referenced column name.
*
* Previously this was a simple task, but with DDC-117 this problem is actually recursive. If its
* not a simple field, go through all identifier field names that are associations recursivly and
@ -493,8 +506,9 @@ class SchemaTool
* TODO: Is there any way to make this code more pleasing?
*
* @param ClassMetadata $class
* @param string $referencedColumnName
* @return array(ClassMetadata, referencedFieldName)
* @param string $referencedColumnName
*
* @return array (ClassMetadata, referencedFieldName)
*/
private function getDefiningClass($class, $referencedColumnName)
{
@ -520,16 +534,20 @@ class SchemaTool
}
/**
* Gather columns and fk constraints that are required for one part of relationship.
* Gathers columns and fk constraints that are required for one part of relationship.
*
* @param array $joinColumns
* @param \Doctrine\DBAL\Schema\Table $theJoinTable
* @param array $joinColumns
* @param Table $theJoinTable
* @param ClassMetadata $class
* @param array $mapping
* @param array $primaryKeyColumns
* @param array $uniqueConstraints
* @param array $addedFks
* @param array $blacklistedFks
* @param array $mapping
* @param array $primaryKeyColumns
* @param array $uniqueConstraints
* @param array $addedFks
* @param array $blacklistedFks
*
* @return void
*
* @throws \Doctrine\ORM\ORMException
*/
private function _gatherRelationJoinColumns($joinColumns, $theJoinTable, $class, $mapping, &$primaryKeyColumns, &$uniqueConstraints, &$addedFks, &$blacklistedFks)
{
@ -625,6 +643,7 @@ class SchemaTool
* issued for all classes of the schema and some probably just don't exist.
*
* @param array $classes
*
* @return void
*/
public function dropSchema(array $classes)
@ -673,9 +692,10 @@ class SchemaTool
}
/**
* Get SQL to drop the tables defined by the passed classes.
* Gets SQL to drop the tables defined by the passed classes.
*
* @param array $classes
*
* @return array
*/
public function getDropSchemaSQL(array $classes)
@ -729,8 +749,9 @@ class SchemaTool
* instances to the current database schema that is inspected. If $saveMode is set
* to true the command is executed in the Database, else SQL is returned.
*
* @param array $classes
* @param array $classes
* @param boolean $saveMode
*
* @return void
*/
public function updateSchema(array $classes, $saveMode = false)
@ -749,8 +770,9 @@ class SchemaTool
* If $saveMode is set to true the command is executed in the Database,
* else SQL is returned.
*
* @param array $classes The classes to consider.
* @param boolean $saveMode True for writing to DB, false for SQL string
* @param array $classes The classes to consider.
* @param boolean $saveMode True for writing to DB, false for SQL string.
*
* @return array The sequence of SQL statements.
*/
public function getUpdateSchemaSql(array $classes, $saveMode = false)

View File

@ -78,9 +78,10 @@ class SchemaValidator
}
/**
* Validate a single class of the current
* Validates a single class of the current.
*
* @param ClassMetadataInfo $class
*
* @return array
*/
public function validateClass(ClassMetadataInfo $class)
@ -255,7 +256,7 @@ class SchemaValidator
}
/**
* Check if the Database Schema is in sync with the current metadata state.
* Checks if the Database Schema is in sync with the current metadata state.
*
* @return bool
*/

View File

@ -38,6 +38,7 @@ class Setup
* its github repository at {@link http://github.com/doctrine/doctrine2}
*
* @param string $gitCheckoutRootPath
*
* @return void
*/
public static function registerAutoloadGit($gitCheckoutRootPath)
@ -90,6 +91,8 @@ class Setup
* Pick the directory the library was uncompressed into.
*
* @param string $directory
*
* @return void
*/
public static function registerAutoloadDirectory($directory)
{
@ -105,13 +108,14 @@ class Setup
}
/**
* Create a configuration with an annotation metadata driver.
* Creates a configuration with an annotation metadata driver.
*
* @param array $paths
* @param array $paths
* @param boolean $isDevMode
* @param string $proxyDir
* @param Cache $cache
* @param bool $useSimpleAnnotationReader
* @param string $proxyDir
* @param Cache $cache
* @param bool $useSimpleAnnotationReader
*
* @return Configuration
*/
public static function createAnnotationMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null, $useSimpleAnnotationReader = true)
@ -123,12 +127,13 @@ class Setup
}
/**
* Create a configuration with a xml metadata driver.
* Creates a configuration with a xml metadata driver.
*
* @param array $paths
* @param array $paths
* @param boolean $isDevMode
* @param string $proxyDir
* @param Cache $cache
* @param string $proxyDir
* @param Cache $cache
*
* @return Configuration
*/
public static function createXMLMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null)
@ -140,12 +145,13 @@ class Setup
}
/**
* Create a configuration with a yaml metadata driver.
* Creates a configuration with a yaml metadata driver.
*
* @param array $paths
* @param array $paths
* @param boolean $isDevMode
* @param string $proxyDir
* @param Cache $cache
* @param string $proxyDir
* @param Cache $cache
*
* @return Configuration
*/
public static function createYAMLMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null)
@ -157,11 +163,12 @@ class Setup
}
/**
* Create a configuration without a metadata driver.
* Creates a configuration without a metadata driver.
*
* @param bool $isDevMode
* @param bool $isDevMode
* @param string $proxyDir
* @param Cache $cache
* @param Cache $cache
*
* @return Configuration
*/
public static function createConfiguration($isDevMode = false, $proxyDir = null, Cache $cache = null)

View File

@ -22,17 +22,28 @@ namespace Doctrine\ORM\Tools;
use Doctrine\ORM\ORMException;
/**
* Tools related Exceptions
* Tools related Exceptions.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class ToolsException extends ORMException
{
/**
* @param string $sql
* @param \Exception $e
*
* @return ToolsException
*/
public static function schemaToolFailure($sql, \Exception $e)
{
return new self("Schema-Tool failed with Error '" . $e->getMessage() . "' while executing DDL: " . $sql, "0", $e);
}
/**
* @param string $type
*
* @return ToolsException
*/
public static function couldNotMapDoctrine1Type($type)
{
return new self("Could not map doctrine 1 type '$type'!");