From 1a20763b03ccc6a46dcedcd491dc7db8627d7243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20A=2E=20L=C3=B3pez=20L=C3=B3pez?= Date: Tue, 10 Sep 2024 15:53:05 -0400 Subject: [PATCH] #213: use the `ListItemContext` for `ListView::beforeItem` and `ListView::afterItem` too. --- src/ListItemContext.php | 7 ++++++- src/ListView.php | 11 +++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ListItemContext.php b/src/ListItemContext.php index 48fe6d3c7..00c8ab656 100644 --- a/src/ListItemContext.php +++ b/src/ListItemContext.php @@ -6,7 +6,12 @@ final class ListItemContext { - + /** + * @param array|object $data The current data being rendered. + * @param int|string $key The key value associated with the current data. + * @param int $index The zero-based index of the data in the array. + * @param ListView $widget The list view object. + */ public function __construct( public readonly array|object $data, public readonly int|string $key, diff --git a/src/ListView.php b/src/ListView.php index af15e25cd..63387a40a 100644 --- a/src/ListView.php +++ b/src/ListView.php @@ -69,14 +69,9 @@ public function afterItem(Closure $value): self * It should have the following signature: * * ```php - * function ($data, $key, $index, $widget) + * function (ListItemContext $context) * ``` * - * - `$data`: The current data being rendered. - * - `$key`: The key value associated with the current data. - * - `$index`: The zero-based index of the data in the array. - * - `$widget`: The list view object. - * * The return result of the function will be rendered directly. * * Note: If the function returns `null`, nothing will be rendered before the item. @@ -325,7 +320,7 @@ private function renderAfterItem(ListItemContext $context): string $result = ''; if (!empty($this->afterItem)) { - $result = (string)call_user_func($this->afterItem, $context->data, $context->key, $context->index, $context->widget); + $result = (string)call_user_func($this->afterItem, $context); } return $result; @@ -347,7 +342,7 @@ private function renderBeforeItem(ListItemContext $context): string $result = ''; if (!empty($this->beforeItem)) { - $result = (string)call_user_func($this->beforeItem, $context->data, $context->key, $context->index, $context->widget); + $result = (string)call_user_func($this->beforeItem, $context); } return $result;