From 6d6c90091e0c4c0863ea5f6a103f1f52d9eedc3c 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 26445ca..5eebcdf 100644 --- a/src/DataSources/MergedDataSource.php +++ b/src/DataSources/MergedDataSource.php @@ -34,9 +34,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.'); }