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