Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7: Validate that DataReader is not both sortable and limited for GridView #215

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/GridView.php
samdark marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
namespace Yiisoft\Yii\DataView;

use Closure;
use InvalidArgumentException;
use Psr\Container\ContainerInterface;
use Stringable;
use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Data\Paginator\PaginatorInterface;
use Yiisoft\Data\Reader\LimitableDataInterface;
use Yiisoft\Data\Reader\ReadableDataInterface;
use Yiisoft\Data\Reader\Sort;
use Yiisoft\Data\Reader\SortableDataInterface;
Expand Down Expand Up @@ -755,4 +757,18 @@ private function getColumnRenderers(): array

return $this->columnRenderersCache;
}

public function dataReader(ReadableDataInterface $dataReader): static
{
if (
$dataReader instanceof LimitableDataInterface
&& $dataReader instanceof SortableDataInterface
&& $dataReader->getLimit() !== null
&& $dataReader->getSort() !== null
) {
throw new InvalidArgumentException('GridView can\'t render both limited and sorted data at the same time.');
}

return parent::dataReader($dataReader);
}
}
Loading