- Added a closure on key to EntityCollection buildArray method.

- Some bugfixes done.
This commit is contained in:
Dave M. 2021-03-29 20:01:31 +00:00
parent 317d62ceaa
commit 1469d167c4
3 changed files with 13 additions and 9 deletions

View File

@ -238,7 +238,7 @@ class EntityResolver {
/** /**
* Transform an annotation into it's object's counterpart * Transform an annotation into it's object's counterpart
*/ */
public function getAnnotationFromClassname(string $className) : ? object public function getAnnotationFromClassname(string $className, bool $throwError = true) : ? object
{ {
if ( $name = $this->uses[$className] ?? false ) { if ( $name = $this->uses[$className] ?? false ) {
@ -264,9 +264,11 @@ class EntityResolver {
} }
} }
throw new \TypeError("Annotation `$className` could not be found within your object `{$this->entityClass}`"); if ($throwError) {
throw new \TypeError("Annotation `$className` could not be found within your object `{$this->entityClass}`");
}
} }
else { elseif ($throwError) {
throw new \InvalidArgumentException("Class `$className` was not found within {$this->entityClass} uses statement (or it's children / traits)"); throw new \InvalidArgumentException("Class `$className` was not found within {$this->entityClass} uses statement (or it's children / traits)");
} }

View File

@ -181,25 +181,27 @@ class EntityCollection extends \ArrayObject {
return $return ?? null; return $return ?? null;
} }
public function buildArray(string $keyColumn, /* string|callable|null */ $value = null) : array public function buildArray(/* string|callable|null */ $keyColumn, /* string|callable|null */ $value = null) : array
{ {
$list = []; $list = [];
foreach($this as $item) { foreach($this as $item) {
$key = $keyColumn instanceof \Closure ? $keyColumn($item) : $item->$keyColumn;
switch (true) { switch (true) {
case is_null($value): case is_null($value):
$list[] = $item->$keyColumn; $list[] = $key;
break; break;
case is_callable($value): case is_callable($value):
$list[$item->$keyColumn] = $value($item); $list[$key] = $value($item);
break; break;
case is_object($value): case is_object($value):
case is_string($value): case is_string($value):
$value = (string) $value; $value = (string) $value;
$list[$item->$keyColumn] = $item->$value; $list[$key] = $item->$value;
break; break;
} }
} }

View File

@ -79,12 +79,12 @@ class Repository
return Ulmus::runSelectQuery($this->queryBuilder, $this->adapter)->fetchColumn(0); return Ulmus::runSelectQuery($this->queryBuilder, $this->adapter)->fetchColumn(0);
} }
protected function deleteOne() public function deleteOne()
{ {
return $this->limit(1)->deleteSqlQuery()->runQuery(); return $this->limit(1)->deleteSqlQuery()->runQuery();
} }
protected function deleteAll() public function deleteAll()
{ {
return $this->deleteSqlQuery()->runQuery(); return $this->deleteSqlQuery()->runQuery();
} }