From d5a9bc32fc67cb15504af8b0191bb42e77d79ab1 Mon Sep 17 00:00:00 2001 From: Jan Pecha Date: Tue, 5 Dec 2023 15:22:16 +0100 Subject: [PATCH] DataSources: MergedDataSource - support class subtypes --- src/DataSources/MergedDataSource.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/DataSources/MergedDataSource.php b/src/DataSources/MergedDataSource.php index 9f35497..5cffb70 100644 --- a/src/DataSources/MergedDataSource.php +++ b/src/DataSources/MergedDataSource.php @@ -32,9 +32,16 @@ public function getRowId($row) if (is_array($row)) { throw new \Inteve\DataGrid\InvalidArgumentException(self::class . ' requires only objects, array given.'); } + $class = get_class($row); if (!isset($this->dataSources[$class])) { + foreach ($this->dataSources as $dataSourceClass => $dataSource) { + if ($row instanceof $dataSourceClass) { + return $dataSource->getRowId($row); + } + } + throw new \Inteve\DataGrid\InvalidArgumentException('Unknow row type, there is no data source for it.'); }