#1272 DDC-2704 - reverting classmetadata API changes (moved all to reflection property getter API)
This commit is contained in:
parent
d952077d04
commit
28e0da4321
@ -20,7 +20,6 @@
|
||||
namespace Doctrine\ORM\Mapping;
|
||||
|
||||
use BadMethodCallException;
|
||||
use Doctrine\Common\Persistence\Mapping\ReflectionService;
|
||||
use Doctrine\Instantiator\Instantiator;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
@ -650,12 +649,6 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
*/
|
||||
private $instantiator;
|
||||
|
||||
/**
|
||||
* @var \ReflectionProperty[]|null (null if not yet initialized) - all instance properties of the class,
|
||||
* transient or not, in accessible form.
|
||||
*/
|
||||
private $reflectionProperties;
|
||||
|
||||
/**
|
||||
* Initializes a new ClassMetadata instance that will hold the object-relational mapping
|
||||
* metadata of the class with the given name.
|
||||
@ -674,30 +667,13 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
/**
|
||||
* Gets the ReflectionProperties of the mapped class.
|
||||
*
|
||||
* @return \ReflectionProperty[] An array of ReflectionProperty instances.
|
||||
* @return array An array of ReflectionProperty instances.
|
||||
*/
|
||||
public function getReflectionProperties()
|
||||
{
|
||||
return $this->reflFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all ReflectionProperties of this class, considering inherited and transient ones
|
||||
*
|
||||
* Note that this method should only be used after `wakeupReflection`
|
||||
*/
|
||||
public function getAllReflectionProperties()
|
||||
{
|
||||
if (null === $this->reflectionProperties) {
|
||||
throw new \RuntimeException(sprintf(
|
||||
'You cannot read the reflection properties before calling %s#wakeupReflection() first',
|
||||
get_class($this)
|
||||
));
|
||||
}
|
||||
|
||||
return $this->reflectionProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a ReflectionProperty for a specific field of the mapped class.
|
||||
*
|
||||
@ -987,8 +963,6 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
? $reflService->getAccessibleProperty($mapping['declared'], $field)
|
||||
: $reflService->getAccessibleProperty($this->name, $field);
|
||||
}
|
||||
|
||||
$this->initializeAllReflectionProperties($reflService);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1009,8 +983,6 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
}
|
||||
|
||||
$this->table['name'] = $this->namingStrategy->classToTableName($this->name);
|
||||
|
||||
$this->initializeAllReflectionProperties($reflService);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3341,56 +3313,4 @@ class ClassMetadataInfo implements ClassMetadata
|
||||
|
||||
return $sequencePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the internal `reflectionProperties` property
|
||||
*
|
||||
* @param ReflectionService $reflectionService
|
||||
*/
|
||||
private function initializeAllReflectionProperties(ReflectionService $reflectionService)
|
||||
{
|
||||
if (! $this->reflClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
$currentClass = $this->reflClass;
|
||||
$properties = array();
|
||||
|
||||
do {
|
||||
$className = $currentClass->getName();
|
||||
|
||||
foreach ($currentClass->getProperties() as $property) {
|
||||
// static properties are not instance properties
|
||||
if ($property->isStatic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// indexing by logical name to avoid duplicates
|
||||
$logicalName = $property->getDeclaringClass()->getName() . '::' . $property->getName();
|
||||
$propertyName = $property->getName();
|
||||
$existingField = isset($this->reflFields[$propertyName]) ? $this->reflFields[$propertyName] : null;
|
||||
|
||||
if (! $existingField) {
|
||||
$properties[$logicalName] = $reflectionService->getAccessibleProperty($className, $propertyName);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// private properties are not inherited: need to handle them separately and precisely
|
||||
if ($property->isPrivate()
|
||||
&& $existingField->getDeclaringClass()->getName() !== $property->getDeclaringClass()->getName()
|
||||
) {
|
||||
$properties[$logicalName] = $reflectionService->getAccessibleProperty($className, $propertyName);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$properties[$logicalName] = $existingField;
|
||||
}
|
||||
|
||||
$parentClass = $currentClass->getParentClass();
|
||||
} while ($parentClass && $currentClass = $reflectionService->getClass($parentClass->getName()));
|
||||
|
||||
$this->reflectionProperties = array_values($properties);
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,9 @@
|
||||
namespace Doctrine\Tests\ORM\Mapping;
|
||||
|
||||
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService;
|
||||
use Doctrine\Common\Persistence\Mapping\StaticReflectionService;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Events;
|
||||
use Doctrine\ORM\Mapping\DefaultNamingStrategy;
|
||||
use Doctrine\Tests\Models\DirectoryTree\AbstractContentItem;
|
||||
use Doctrine\Tests\Models\DirectoryTree\File;
|
||||
|
||||
require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php';
|
||||
|
||||
@ -1128,73 +1125,6 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-2704
|
||||
*/
|
||||
public function testGetAllReflectionPropertiesFailsOnNonInitializedMetadata()
|
||||
{
|
||||
$classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity');
|
||||
|
||||
$this->setExpectedException('RuntimeException');
|
||||
|
||||
$classMetadata->getAllReflectionProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-2704
|
||||
*/
|
||||
public function testGetAllReflectionPropertiesFailsOnPartiallyInitializedMetadata()
|
||||
{
|
||||
$classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity');
|
||||
|
||||
$classMetadata->initializeReflection(new StaticReflectionService());
|
||||
|
||||
$this->setExpectedException('RuntimeException');
|
||||
|
||||
$classMetadata->getAllReflectionProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-2704
|
||||
*/
|
||||
public function testGetAllReflectionPropertiesRetrievesCollidingPrivateProperties()
|
||||
{
|
||||
$classMetadata = new ClassMetadata(File::CLASSNAME);
|
||||
|
||||
$classMetadata->initializeReflection(new RuntimeReflectionService());
|
||||
|
||||
$properties = $classMetadata->getAllReflectionProperties();
|
||||
|
||||
$this->assertInternalType('array', $properties);
|
||||
$this->assertCount(5, $properties);
|
||||
|
||||
$propertyNames = array_map(
|
||||
function (\ReflectionProperty $property) {
|
||||
return $property->getDeclaringClass()->getName() . '::' . $property->getName();
|
||||
},
|
||||
$properties
|
||||
);
|
||||
|
||||
sort($propertyNames);
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
'Doctrine\Tests\Models\DirectoryTree\AbstractContentItem::id',
|
||||
'Doctrine\Tests\Models\DirectoryTree\AbstractContentItem::name',
|
||||
'Doctrine\Tests\Models\DirectoryTree\AbstractContentItem::nodeIsLoaded',
|
||||
'Doctrine\Tests\Models\DirectoryTree\AbstractContentItem::parentDirectory',
|
||||
'Doctrine\Tests\Models\DirectoryTree\File::extension',
|
||||
],
|
||||
$propertyNames
|
||||
);
|
||||
|
||||
$this->assertNotContains(
|
||||
'Doctrine\Tests\Models\DirectoryTree\AbstractContentItem::fileSystem',
|
||||
$propertyNames,
|
||||
'Abstract properties should not be part of class metadata information'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user