Skip to content

Commit

Permalink
Reusing chained driver now available in common, fixing cs/code smells…
Browse files Browse the repository at this point in the history
… and removing duplicate docs.
  • Loading branch information
Ocramius committed Jul 4, 2012
1 parent 97d7cae commit 379e698
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 168 deletions.
17 changes: 2 additions & 15 deletions lib/Doctrine/ORM/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,9 @@
namespace Doctrine\ORM\Mapping;

/**
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
* of an entity and it's associations.
* {@inheritDoc}
*
* Once populated, ClassMetadata instances are usually cached in a serialized form.
*
* <b>IMPORTANT NOTE:</b>
*
* The fields of this class are only public for 2 reasons:
* 1) To allow fast READ access.
* 2) To drastically reduce the size of a serialized instance (private/protected members
* get the whole class name, namespace inclusive, prepended to every property in
* the serialized representation).
*
* @author Roman Borschel <[email protected]>
* @author Jonathan H. Wage <[email protected]>
* @since 2.0
* @todo remove or rename ClassMetadataInfo to ClassMetadata
*/
class ClassMetadata extends ClassMetadataInfo
{
Expand Down
62 changes: 15 additions & 47 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,7 @@ public function validateLifecycleCallbacks($reflService)
}

/**
* Gets the ReflectionClass instance of the mapped class.
*
* @return ReflectionClass
* {@inheritDoc}
*/
public function getReflectionClass()
{
Expand Down Expand Up @@ -1547,9 +1545,7 @@ protected function _validateAndCompleteManyToManyMapping(array $mapping)
}

/**
* Gets the identifier (primary key) field names of the class.
*
* @return mixed
* {@inheritDoc}
*/
public function getIdentifierFieldNames()
{
Expand Down Expand Up @@ -1607,10 +1603,7 @@ public function getIdentifier()
}

/**
* Checks whether the class has a (mapped) field with a certain name.
*
* @param string $fieldName
* @return bool
* {@inheritDoc}
*/
public function hasField($fieldName)
{
Expand Down Expand Up @@ -2080,7 +2073,7 @@ public function addInheritedAssociationMapping(array $mapping/*, $owningClassNam
* Adds a field mapping without completing/validating it.
* This is mainly used to add inherited field mappings to derived classes.
*
* @internal param array $fieldMapping
* @param array $fieldMapping
* @return void
*/
public function addInheritedFieldMapping(array $fieldMapping)
Expand Down Expand Up @@ -2292,7 +2285,8 @@ protected function _storeAssociationMapping(array $assocMapping)
/**
* Registers a custom repository class for the entity class.
*
* @param string $mapperClassName The class name of the custom mapper.
* @param string $repositoryClassName The class name of the custom mapper.
* @return void
*/
public function setCustomRepositoryClass($repositoryClassName)
{
Expand Down Expand Up @@ -2474,22 +2468,15 @@ public function hasSqlResultSetMapping($name)
}

/**
* Checks whether the class has a mapped association with the given field name.
*
* @param string $fieldName
* @return boolean
* {@inheritDoc}
*/
public function hasAssociation($fieldName)
{
return isset($this->associationMappings[$fieldName]);
}

/**
* Checks whether the class has a mapped association for the specified field
* and if yes, checks whether it is a single-valued association (to-one).
*
* @param string $fieldName
* @return boolean TRUE if the association exists and is single-valued, FALSE otherwise.
* {@inheritDoc}
*/
public function isSingleValuedAssociation($fieldName)
{
Expand All @@ -2498,11 +2485,7 @@ public function isSingleValuedAssociation($fieldName)
}

/**
* Checks whether the class has a mapped association for the specified field
* and if yes, checks whether it is a collection-valued association (to-many).
*
* @param string $fieldName
* @return boolean TRUE if the association exists and is collection-valued, FALSE otherwise.
* {@inheritDoc}
*/
public function isCollectionValuedAssociation($fieldName)
{
Expand Down Expand Up @@ -2681,35 +2664,24 @@ public function markReadOnly()
}

/**
* A numerically indexed list of field names of this persistent class.
*
* This array includes identifier fields if present on this class.
*
* @return array
* {@inheritDoc}
*/
public function getFieldNames()
{
return array_keys($this->fieldMappings);
}

/**
* A numerically indexed list of association names of this persistent class.
*
* This array includes identifier associations if present on this class.
*
* @return array
* {@inheritDoc}
*/
public function getAssociationNames()
{
return array_keys($this->associationMappings);
}

/**
* Returns the target class name of the given association.
*
* @param string $assocName
* {@inheritDoc}
* @throws InvalidArgumentException
* @return string
*/
public function getAssociationTargetClass($assocName)
{
Expand All @@ -2721,9 +2693,7 @@ public function getAssociationTargetClass($assocName)
}

/**
* Get fully-qualified class name of this persistent class.
*
* @return string
* {@inheritDoc}
*/
public function getName()
{
Expand Down Expand Up @@ -2812,17 +2782,15 @@ public function getQuotedJoinTableName(array $assoc, $platform)
}

/**
* @param string $fieldName
* @return bool
* {@inheritDoc}
*/
public function isAssociationInverseSide($fieldName)
{
return isset($this->associationMappings[$fieldName]) && ! $this->associationMappings[$fieldName]['isOwningSide'];
}

/**
* @param string $fieldName
* @return string
* {@inheritDoc}
*/
public function getAssociationMappedByTargetField($fieldName)
{
Expand Down
10 changes: 6 additions & 4 deletions lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@
class AnnotationDriver extends AbstractAnnotationDriver
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
protected $entityAnnotationClasses = array(
'Doctrine\ORM\Mapping\Entity' => 1,
'Doctrine\ORM\Mapping\MappedSuperclass' => 2,
);

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
/* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */
$class = $metadata->getReflectionClass();
if ( ! $class) {
// this happens when running annotation driver in combination with
Expand Down Expand Up @@ -264,6 +265,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
}

// Evaluate annotations on properties/fields
/* @var $property \ReflectionProperty */
foreach ($class->getProperties() as $property) {
if ($metadata->isMappedSuperclass && ! $property->isPrivate()
||
Expand Down Expand Up @@ -437,7 +439,6 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
}
}

$attributeOverrides = array();
// Evaluate AttributeOverrides annotation
if (isset($classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides'])) {
$attributeOverridesAnnot = $classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides'];
Expand All @@ -449,6 +450,7 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)

// Evaluate @HasLifecycleCallbacks annotation
if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
/* @var $method \ReflectionMethod */
foreach ($class->getMethods() as $method) {
// filter for the declaring class only, callbacks from parents will already be registered.
if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) {
Expand Down Expand Up @@ -576,8 +578,8 @@ static public function create($paths = array(), AnnotationReader $reader = null)
{
if ($reader == null) {
$reader = new AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
}

return new self($reader, $paths);
}
}
10 changes: 3 additions & 7 deletions lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private function reverseEngineerMappingFromDatabase()
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function loadMetadataForClass($className, ClassMetadata $metadata)
{
Expand Down Expand Up @@ -318,19 +318,15 @@ public function loadMetadataForClass($className, ClassMetadata $metadata)
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function isTransient($className)
{
return true;
}

/**
* Return all the class names supported by this driver.
*
* IMPORTANT: This method must return an array of class not tables names.
*
* @return array
* {@inheritDoc}
*/
public function getAllClassNames()
{
Expand Down
Loading

0 comments on commit 379e698

Please sign in to comment.