- Added ArrayOf attributes and DatasetFill/DatasetPull events. ArrayCollection is also working with ArrayOf attributes
This commit is contained in:
1 parent
fd5d31fa17
commit
009e30eb7e
21 files changed
+322
-43
No files matched your search
+27
-13
@@ -199,7 +199,7 @@ class Repository implements RepositoryInterface
|
||||
public function save(object|array $entity, ? array $fieldsAndValue = null, bool $replace = false) : bool
|
||||
{
|
||||
if ( is_array($entity) ) {
|
||||
$entity = ( new $this->entityClass() )->fromArray($entity);
|
||||
$entity = new $this->entityClass($entity);
|
||||
}
|
||||
|
||||
if ( ! $this->matchEntity($entity) ) {
|
||||
@@ -245,6 +245,8 @@ class Repository implements RepositoryInterface
|
||||
|
||||
$diff = $fieldsAndValue ?? $this->generateWritableDataset($entity);
|
||||
|
||||
# dump($diff);
|
||||
|
||||
if ( [] !== $diff ) {
|
||||
if ($primaryKeyDefinition) {
|
||||
$pkField = key($primaryKeyDefinition);
|
||||
@@ -457,14 +459,12 @@ class Repository implements RepositoryInterface
|
||||
$this->select($this->entityClass::fields(array_map(fn($f) => $f['object']->name ?? $f['name'], $select)));
|
||||
}
|
||||
|
||||
# @TODO Apply FILTER annotation to this too !
|
||||
foreach(array_filter((array) $fields) as $item) {
|
||||
if ( isset($this->joined[$item]) ) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
$this->joined[$item] = true;
|
||||
}
|
||||
$fields = (array) $fields;
|
||||
usort($fields, fn($e1, $e2) => str_contains($e1, '.') <=> str_contains($e2, '.'));
|
||||
|
||||
# @TODO Apply fff annotation to this too !
|
||||
foreach(array_filter($fields, fn($e) => $e && ! isset($this->joined[$e]) ) as $item) {
|
||||
$this->joined[$item] = true;
|
||||
|
||||
$attribute = $this->entityResolver->searchFieldAnnotation($item, [ Join::class ]) ?:
|
||||
$this->entityResolver->searchFieldAnnotation($item, [ Relation::class ]);
|
||||
@@ -682,9 +682,15 @@ class Repository implements RepositoryInterface
|
||||
{
|
||||
if ($count) {
|
||||
$searchRequest->applyCount($this->serverRequestCountRepository());
|
||||
}
|
||||
|
||||
$searchRequest->apply($this);
|
||||
# @TODO Handle no request to do if count is 0 here
|
||||
#if ($searchRequest->count) {
|
||||
$searchRequest->apply($this);
|
||||
# }
|
||||
}
|
||||
else {
|
||||
$searchRequest->apply($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -772,9 +778,17 @@ class Repository implements RepositoryInterface
|
||||
return $this->entityClass::entityCollection(...$arguments);
|
||||
}
|
||||
|
||||
public function instanciateEntity(? string $entityClass = null) : object
|
||||
public function instanciateEntity(? string $entityClass = null, array $dataset = []) : object
|
||||
{
|
||||
$entity = ( new \ReflectionClass($entityClass ?? $this->entityClass) )->newInstanceWithoutConstructor();
|
||||
$entityClass ??= $this->entityClass;
|
||||
|
||||
try {
|
||||
$entity = new $entityClass($dataset);
|
||||
}
|
||||
catch (\Throwable $ex) {
|
||||
$entity = ( new \ReflectionClass($entityClass) )->newInstanceWithoutConstructor()->fromArray($dataset);
|
||||
}
|
||||
|
||||
$entity->initializeEntity();
|
||||
|
||||
return $entity;
|
||||
|
||||
Reference in new issue
Block a user