Merge branch 'master' of https://git.mcnd.ca/mcndave/ulmus
This commit is contained in:
commit
ab1d7e4f5b
9 files changed
+56
-37
No files matched your search
+18
-18
@@ -66,7 +66,7 @@ trait EntityTrait {
|
||||
$data = json_decode($value, true);
|
||||
|
||||
if (json_last_error() !== \JSON_ERROR_NONE) {
|
||||
throw new \Exception(sprintf("JSON error while decoding in EntityTrait : '%s' given %s with field %s", json_last_error_msg(), $value, json_encode($field)));
|
||||
throw new \Exception(sprintf("JSON error while decoding in EntityTrait : '%s' given %s", json_last_error_msg(), $value));
|
||||
}
|
||||
|
||||
$this->{$field['name']} = $data;
|
||||
@@ -116,7 +116,7 @@ trait EntityTrait {
|
||||
$this->entityLoadedDataset = array_change_key_case($dataset, \CASE_LOWER);
|
||||
}
|
||||
elseif ($overwriteDataset) {
|
||||
$this->entityLoadedDataset = array_change_key_case($dataset, \CASE_LOWER) + $this->entityLoadedDataset;
|
||||
$this->entityLoadedDataset = iterator_to_array(array_change_key_case($dataset, \CASE_LOWER)) + $this->entityLoadedDataset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,11 +127,9 @@ trait EntityTrait {
|
||||
public function resetVirtualProperties() : self
|
||||
{
|
||||
foreach($this->resolveEntity()->properties as $prop => $property) {
|
||||
if ( empty($property['builtin']) ) {
|
||||
foreach($property['tags'] as $tag) {
|
||||
if ( in_array(strtolower($tag['tag']), [ 'relation', 'join', 'virtual' ] ) ) {
|
||||
unset($this->$prop);
|
||||
}
|
||||
foreach($property['tags'] as $tag) {
|
||||
if ( in_array(strtolower($tag['tag']), [ 'relation', 'join', 'virtual' ] ) ) {
|
||||
unset($this->$prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,7 +143,7 @@ trait EntityTrait {
|
||||
return $this->entityFillFromDataset($dataset);
|
||||
}
|
||||
|
||||
public function entityGetDataset(bool $includeRelations = false, bool $returnSource = false) : array
|
||||
public function entityGetDataset(bool $includeRelations = false, bool $returnSource = false, bool $rewriteValue = true) : array
|
||||
{
|
||||
if ( $returnSource ) {
|
||||
return $this->entityLoadedDataset;
|
||||
@@ -159,7 +157,10 @@ trait EntityTrait {
|
||||
$annotation = $entityResolver->searchFieldAnnotation($key, [ Attribute\Property\Field::class, Field::class ]);
|
||||
|
||||
if ( isset($this->$key) ) {
|
||||
$dataset[$annotation->name ?? $key] = static::repository()->adapter->adapter()->writableValue($this->$key);
|
||||
$dataset[$annotation->name ?? $key] = $rewriteValue?
|
||||
static::repository()->adapter->adapter()->writableValue($this->$key)
|
||||
:
|
||||
$this->$key;
|
||||
}
|
||||
elseif ( $field['nullable'] ) {
|
||||
$dataset[$annotation->name ?? $key] = null;
|
||||
@@ -169,7 +170,7 @@ trait EntityTrait {
|
||||
# @TODO Must fix recursive bug !
|
||||
if ($includeRelations) {
|
||||
foreach($entityResolver->properties as $name => $field){
|
||||
$relation = $entityResolver->searchFieldAnnotation($key, [ Attribute\Property\Relation::class. Relation::class ] );
|
||||
$relation = $entityResolver->searchFieldAnnotation($name, [ Attribute\Property\Relation::class, Relation::class ] );
|
||||
|
||||
if ( $relation && isset($this->$name) && ($relation->entity ?? $relation->bridge) !== static::class ) {
|
||||
if ( null !== $value = $this->$name ?? null ) {
|
||||
@@ -196,7 +197,7 @@ trait EntityTrait {
|
||||
#[Ignore]
|
||||
public function toArray($includeRelations = false, array $filterFields = null) : array
|
||||
{
|
||||
$dataset = $this->entityGetDataset($includeRelations);
|
||||
$dataset = $this->entityGetDataset($includeRelations, false, false);
|
||||
|
||||
return $filterFields ? array_intersect_key($dataset, array_flip($filterFields)) : $dataset;
|
||||
}
|
||||
@@ -265,10 +266,6 @@ trait EntityTrait {
|
||||
#[Ignore]
|
||||
public function __clone()
|
||||
{
|
||||
foreach($this as $prop) {
|
||||
|
||||
}
|
||||
|
||||
if ( null !== $pkField = $this->resolveEntity()->getPrimaryKeyField($this) ) {
|
||||
$key = key($pkField);
|
||||
|
||||
@@ -279,7 +276,7 @@ trait EntityTrait {
|
||||
#[Ignore]
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return $this->entityGetDataset();
|
||||
return $this->entityGetDataset(true, false, false);
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
@@ -310,9 +307,12 @@ trait EntityTrait {
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
public static function field($name, null|string|bool $alias = Repository::DEFAULT_ALIAS) : EntityField
|
||||
public static function field($name, null|string|false $alias = Repository::DEFAULT_ALIAS) : EntityField
|
||||
{
|
||||
return new EntityField(static::class, $name, $alias ? Ulmus::repository(static::class)->adapter->adapter()->escapeIdentifier($alias, Adapter\AdapterInterface::IDENTIFIER_FIELD) : ( $alias === false ? '' : Repository::DEFAULT_ALIAS ), Ulmus::resolveEntity(static::class));
|
||||
|
||||
$default = ( $alias === false ? '' : Repository::DEFAULT_ALIAS ); # bw compatibility, to be deprecated
|
||||
|
||||
return new EntityField(static::class, $name, $alias ? Ulmus::repository(static::class)->adapter->adapter()->escapeIdentifier($alias, Adapter\AdapterInterface::IDENTIFIER_FIELD) : $default, Ulmus::resolveEntity(static::class));
|
||||
}
|
||||
|
||||
#[Ignore]
|
||||
|
||||
Reference in new issue
Block a user