- Added a closure on key to EntityCollection buildArray method.
- Some bugfixes done.
This commit is contained in:
parent
317d62ceaa
commit
1469d167c4
|
@ -238,7 +238,7 @@ class EntityResolver {
|
|||
/**
|
||||
* 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 ) {
|
||||
|
||||
|
@ -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)");
|
||||
}
|
||||
|
||||
|
|
|
@ -181,25 +181,27 @@ class EntityCollection extends \ArrayObject {
|
|||
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 = [];
|
||||
|
||||
foreach($this as $item) {
|
||||
$key = $keyColumn instanceof \Closure ? $keyColumn($item) : $item->$keyColumn;
|
||||
|
||||
switch (true) {
|
||||
case is_null($value):
|
||||
$list[] = $item->$keyColumn;
|
||||
$list[] = $key;
|
||||
break;
|
||||
|
||||
case is_callable($value):
|
||||
$list[$item->$keyColumn] = $value($item);
|
||||
$list[$key] = $value($item);
|
||||
break;
|
||||
|
||||
case is_object($value):
|
||||
case is_string($value):
|
||||
$value = (string) $value;
|
||||
|
||||
$list[$item->$keyColumn] = $item->$value;
|
||||
$list[$key] = $item->$value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,12 +79,12 @@ class Repository
|
|||
return Ulmus::runSelectQuery($this->queryBuilder, $this->adapter)->fetchColumn(0);
|
||||
}
|
||||
|
||||
protected function deleteOne()
|
||||
public function deleteOne()
|
||||
{
|
||||
return $this->limit(1)->deleteSqlQuery()->runQuery();
|
||||
}
|
||||
|
||||
protected function deleteAll()
|
||||
public function deleteAll()
|
||||
{
|
||||
return $this->deleteSqlQuery()->runQuery();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue