mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-14 07:28:41 +00:00
Fixed various errors
This commit is contained in:
parent
2b4d9ae7a5
commit
773d3a962f
|
|
@ -338,13 +338,12 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
|
|
||||||
$reflectionClass = new \ReflectionClass(get_class($obj));
|
$reflectionClass = new \ReflectionClass(get_class($obj));
|
||||||
$objId = self::createModel($reflectionClass, $obj);
|
$objId = self::createModel($reflectionClass, $obj);
|
||||||
|
self::setObjectId($reflectionClass, $obj, $objId);
|
||||||
|
|
||||||
if ($relations === RelationType::ALL) {
|
if ($relations === RelationType::ALL) {
|
||||||
self::createHasMany($reflectionClass, $obj, $objId);
|
self::createHasMany($reflectionClass, $obj, $objId);
|
||||||
}
|
}
|
||||||
|
|
||||||
self::setObjectId($reflectionClass, $obj, $objId);
|
|
||||||
|
|
||||||
return $objId;
|
return $objId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -379,7 +378,7 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
|
|
||||||
foreach (static::$columns as $key => $column) {
|
foreach (static::$columns as $key => $column) {
|
||||||
if (isset(static::$ownsOne[$propertyName]) && $column['internal'] === $propertyName) {
|
if (isset(static::$ownsOne[$propertyName]) && $column['internal'] === $propertyName) {
|
||||||
$id = self::createOwnsOne($propertyName, $property, $obj);
|
$id = self::createOwnsOne($propertyName, $property->getValue($obj));
|
||||||
$value = self::parseValue($column['type'], $id);
|
$value = self::parseValue($column['type'], $id);
|
||||||
|
|
||||||
$query->insert($column['name'])->value($value, $column['type']);
|
$query->insert($column['name'])->value($value, $column['type']);
|
||||||
|
|
@ -458,19 +457,26 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
$property->setAccessible(false);
|
$property->setAccessible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_object($temp = reset($values))) {
|
|
||||||
throw new \Exception('Unexpected value for relational data mapping.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
if (!isset(static::$hasMany[$propertyName]['mapper'])) {
|
||||||
throw new \Exception('No mapper set for relation object.');
|
throw new \Exception('No mapper set for relation object.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapper = static::$hasMany[$propertyName]['mapper'];
|
$mapper = static::$hasMany[$propertyName]['mapper'];
|
||||||
$objsIds = [];
|
$objsIds = [];
|
||||||
$relReflectionClass = new \ReflectionClass(get_class($temp));
|
$relReflectionClass = null;
|
||||||
|
|
||||||
foreach ($values as $key => &$value) {
|
foreach ($values as $key => &$value) {
|
||||||
|
if (!is_object($value)) {
|
||||||
|
// Is scalar => already in database
|
||||||
|
$objsIds[$key] = $value;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($relReflectionClass)) {
|
||||||
|
$relReflectionClass = new \ReflectionClass(get_class($value));
|
||||||
|
}
|
||||||
|
|
||||||
/** @noinspection PhpUndefinedVariableInspection */
|
/** @noinspection PhpUndefinedVariableInspection */
|
||||||
$relProperty = $relReflectionClass->getProperty($mapper::$columns[$mapper::$primaryField]['internal']);
|
$relProperty = $relReflectionClass->getProperty($mapper::$columns[$mapper::$primaryField]['internal']);
|
||||||
|
|
||||||
|
|
@ -486,6 +492,8 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
|
|
||||||
// already in db
|
// already in db
|
||||||
if (!empty($primaryKey)) {
|
if (!empty($primaryKey)) {
|
||||||
|
$objsIds[$key] = $value;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -524,9 +532,8 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
*
|
*
|
||||||
* The reference is stored in the main model
|
* The reference is stored in the main model
|
||||||
*
|
*
|
||||||
* @param string $propertyName Property name to initialize
|
* @param string $propertyName Property name to initialize
|
||||||
* @param \ReflectionProperty $property Reflection property
|
* @param Object $obj Object to create
|
||||||
* @param Object $obj Object to create
|
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*
|
*
|
||||||
|
|
@ -535,25 +542,25 @@ class DataMapperAbstract implements DataMapperInterface
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
private static function createOwnsOne(string $propertyName, \ReflectionProperty $property, $obj)
|
private static function createOwnsOne(string $propertyName, $obj)
|
||||||
{
|
{
|
||||||
if (is_object($relObj = $property->getValue($obj))) {
|
if (is_object($obj)) {
|
||||||
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
$mapper = static::$ownsOne[$propertyName]['mapper'];
|
||||||
$relReflectionClass = new \ReflectionClass(get_class($relObj));
|
$relReflectionClass = new \ReflectionClass(get_class($obj));
|
||||||
/** @var array $columns */
|
/** @var array $columns */
|
||||||
$relProperty = $relReflectionClass->getProperty($mapper::$columns[$mapper::$primaryField]['internal']);
|
$relProperty = $relReflectionClass->getProperty($mapper::$columns[$mapper::$primaryField]['internal']);
|
||||||
$relProperty->setAccessible(true);
|
$relProperty->setAccessible(true);
|
||||||
$primaryKey = $relProperty->getValue($relObj);
|
$primaryKey = $relProperty->getValue($obj);
|
||||||
$relProperty->setAccessible(false);
|
$relProperty->setAccessible(false);
|
||||||
|
|
||||||
if (empty($primaryKey)) {
|
if (empty($primaryKey)) {
|
||||||
$primaryKey = $mapper::create($property->getValue($obj));
|
$primaryKey = $mapper::create($obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $primaryKey;
|
return $primaryKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user