- Added a closure on key to EntityCollection buildArray method.
- Some bugfixes done.
This commit is contained in:
1 parent
317d62ceaa
commit
1469d167c4
3 files changed
+13
-9
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user