Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f247253f9e
@ -143,6 +143,22 @@ trait ObjectArrayLINQTrait
|
||||
* @return array Ассоциированный массив с результатом выборки.
|
||||
*/
|
||||
public function GetColumn (string $column, ?callable $wherePredicate = null): array
|
||||
{
|
||||
return $this->GetColumnCallback(fn ($item) => property_exists($item, $column) ? $item->$column : null,
|
||||
$wherePredicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает колонку в массиве данных.
|
||||
*
|
||||
* @param callable $columnPredicate Функция <code>fn (mixed $item): mixed</code>, возвращающая значение элемента
|
||||
* колонки.
|
||||
* @param callable|null $wherePredicate Условие выборки <code>fn (mixed $item): bool</code>, которое проверяет,
|
||||
* подходит элемент или нет.
|
||||
*
|
||||
* @return array Ассоциированный массив с результатом выборки.
|
||||
*/
|
||||
public function GetColumnCallback (callable $columnPredicate, ?callable $wherePredicate = null): array
|
||||
{
|
||||
// Создаю результат
|
||||
$result = [];
|
||||
@ -153,16 +169,12 @@ trait ObjectArrayLINQTrait
|
||||
if (!is_object($item))
|
||||
continue;
|
||||
|
||||
// - пропускаю не имеющие требуемого свойства
|
||||
if (!property_exists($item, $column))
|
||||
continue;
|
||||
|
||||
// - пропускаю не удовлетворяющие условию
|
||||
if ($wherePredicate !== null && !$wherePredicate($item))
|
||||
continue;
|
||||
|
||||
// - добавляю значение свойства в результат
|
||||
$result[] = $item->$column;
|
||||
$result[] = $columnPredicate($item);
|
||||
}
|
||||
|
||||
// Возвращаю результат
|
||||
|
Loading…
x
Reference in New Issue
Block a user