|
@@ 46-104 (lines=59) @@
|
| 43 |
|
$this->dbalDataLoader = $dbalDataLoader; |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
public function hydrateEntity($entity, EntityManagerInterface $entityManager): void |
| 47 |
|
{ |
| 48 |
|
/** @var string $className */ |
| 49 |
|
$className = get_class($entity); |
| 50 |
|
|
| 51 |
|
if (class_exists(ClassUtils::class)) { |
| 52 |
|
$className = ClassUtils::getRealClass($className); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
$classReflection = new ReflectionClass($className); |
| 56 |
|
|
| 57 |
|
/** @var ?EntityMappingInterface $mapping */ |
| 58 |
|
$mapping = $this->mappingDriver->loadRDMMetadataForClass($className); |
| 59 |
|
|
| 60 |
|
/** @var array<string> $dataFromAdditionalColumns */ |
| 61 |
|
$dataFromAdditionalColumns = array(); |
| 62 |
|
|
| 63 |
|
if ($mapping instanceof EntityMappingInterface) { |
| 64 |
|
if (!empty($mapping->collectDBALColumns())) { |
| 65 |
|
$dataFromAdditionalColumns = $this->dbalDataLoader->loadDBALDataForEntity( |
| 66 |
|
$entity, |
| 67 |
|
$entityManager |
| 68 |
|
); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
if ($mapping instanceof EntityMappingInterface) { |
| 72 |
|
$context = new HydrationContext($entity, $entityManager); |
| 73 |
|
|
| 74 |
|
foreach ($mapping->getFieldMappings() as $fieldName => $fieldMapping) { |
| 75 |
|
/** @var MappingInterface $fieldMapping */ |
| 76 |
|
|
| 77 |
|
/** @var mixed $value */ |
| 78 |
|
$value = $fieldMapping->resolveValue( |
| 79 |
|
$context, |
| 80 |
|
$dataFromAdditionalColumns |
| 81 |
|
); |
| 82 |
|
|
| 83 |
|
/** @var ReflectionClass $concreteClassReflection */ |
| 84 |
|
$concreteClassReflection = $classReflection; |
| 85 |
|
|
| 86 |
|
while (!$concreteClassReflection->hasProperty($fieldName)) { |
| 87 |
|
$concreteClassReflection = $concreteClassReflection->getParentClass(); |
| 88 |
|
|
| 89 |
|
Assert::notNull($concreteClassReflection, sprintf( |
| 90 |
|
"Property '%s' does not exist on object of class '%s'!", |
| 91 |
|
$fieldName, |
| 92 |
|
$className |
| 93 |
|
)); |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
/** @var ReflectionProperty $propertyReflection */ |
| 97 |
|
$propertyReflection = $concreteClassReflection->getProperty($fieldName); |
| 98 |
|
|
| 99 |
|
$propertyReflection->setAccessible(true); |
| 100 |
|
$propertyReflection->setValue($entity, $value); |
| 101 |
|
} |
| 102 |
|
} |
| 103 |
|
} |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
public function assertHydrationOnEntity($entity, EntityManagerInterface $entityManager): void |
| 107 |
|
{ |
|
@@ 106-166 (lines=61) @@
|
| 103 |
|
} |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
public function assertHydrationOnEntity($entity, EntityManagerInterface $entityManager): void |
| 107 |
|
{ |
| 108 |
|
/** @var string $className */ |
| 109 |
|
$className = get_class($entity); |
| 110 |
|
|
| 111 |
|
if (class_exists(ClassUtils::class)) { |
| 112 |
|
$className = ClassUtils::getRealClass($className); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
$classReflection = new ReflectionClass($className); |
| 116 |
|
|
| 117 |
|
/** @var ?EntityMappingInterface $mapping */ |
| 118 |
|
$mapping = $this->mappingDriver->loadRDMMetadataForClass($className); |
| 119 |
|
|
| 120 |
|
/** @var array<string> $dataFromAdditionalColumns */ |
| 121 |
|
$dataFromAdditionalColumns = array(); |
| 122 |
|
|
| 123 |
|
if ($mapping instanceof EntityMappingInterface) { |
| 124 |
|
if (!empty($mapping->collectDBALColumns())) { |
| 125 |
|
$dataFromAdditionalColumns = $this->dbalDataLoader->loadDBALDataForEntity( |
| 126 |
|
$entity, |
| 127 |
|
$entityManager |
| 128 |
|
); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
if ($mapping instanceof EntityMappingInterface) { |
| 132 |
|
$context = new HydrationContext($entity, $entityManager); |
| 133 |
|
|
| 134 |
|
foreach ($mapping->getFieldMappings() as $fieldName => $fieldMapping) { |
| 135 |
|
/** @var MappingInterface $fieldMapping */ |
| 136 |
|
|
| 137 |
|
/** @var ReflectionClass $concreteClassReflection */ |
| 138 |
|
$concreteClassReflection = $classReflection; |
| 139 |
|
|
| 140 |
|
while (!$concreteClassReflection->hasProperty($fieldName)) { |
| 141 |
|
$concreteClassReflection = $concreteClassReflection->getParentClass(); |
| 142 |
|
|
| 143 |
|
Assert::notNull($concreteClassReflection, sprintf( |
| 144 |
|
"Property '%s' does not exist on object of class '%s'!", |
| 145 |
|
$fieldName, |
| 146 |
|
$className |
| 147 |
|
)); |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
/** @var ReflectionProperty $propertyReflection */ |
| 151 |
|
$propertyReflection = $concreteClassReflection->getProperty($fieldName); |
| 152 |
|
|
| 153 |
|
$propertyReflection->setAccessible(true); |
| 154 |
|
|
| 155 |
|
/** @var object $actualValue */ |
| 156 |
|
$actualValue = $propertyReflection->getValue($entity); |
| 157 |
|
|
| 158 |
|
$fieldMapping->assertValue( |
| 159 |
|
$context, |
| 160 |
|
$dataFromAdditionalColumns, |
| 161 |
|
$actualValue |
| 162 |
|
); |
| 163 |
|
} |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
} |
| 167 |
|
|
| 168 |
|
} |
| 169 |
|
|