entity = $entity; } public function serialize(array $columnsToSerialize = [] ): array { $entity = $this->entity; $columns = ColumnMapper::getColumns(get_class($entity)); $reflection = new \ReflectionClass($entity); $dbData = []; foreach ($columns as $column) { if (!empty($columnsToSerialize) && !in_array($column->getProperty(), $columnsToSerialize)) { continue; } try { if (false !== ($reflectionParent = $reflection->getParentClass()) && $reflectionParent->hasProperty($column->getProperty())) { $property = $reflectionParent->getProperty($column->getProperty()); }else { $property = $reflection->getProperty($column->getProperty()); } } catch (\ReflectionException $e) { throw new \InvalidArgumentException("Property {$column->getProperty()} not found in class " . get_class($entity)); } $property->setAccessible(true); $key = sprintf('`%s`', $column->getName()); $value = $property->getValue($entity); if ($column instanceof JoinColumn) { if (is_object($value) && ($value instanceof EntityInterface || method_exists($value, 'getPrimaryKeyValue'))) { $value = $value->getPrimaryKeyValue(); } } $dbData[$key] = $column->convertToDatabase($value) ; } return $dbData; } }