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

Specify button renderer callable type #143

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/Column/ActionColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* the items.
*
* @psalm-type UrlCreator = callable(string,DataContext):string
* @psalm-type ButtonRenderer = callable(string):string
*/
final class ActionColumn implements ColumnInterface
{
Expand All @@ -25,7 +26,7 @@ final class ActionColumn implements ColumnInterface
* @param ?callable $urlCreator A callback that creates a button URL using the specified data information.
*
* @psalm-param UrlCreator|null $urlCreator
* @psalm-param array<string,Closure> $buttons
* @psalm-param array<string,ButtonRenderer> $buttons
* @psalm-param array<string,bool|Closure>|null $visibleButtons
*/
public function __construct(
Expand Down
8 changes: 4 additions & 4 deletions src/Column/ActionColumnRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Yiisoft\Yii\DataView\Column;

use Closure;
use InvalidArgumentException;
use LogicException;
use Yiisoft\Html\Html;
Expand All @@ -14,6 +13,7 @@

/**
* @psalm-import-type UrlCreator from ActionColumn
* @psalm-import-type ButtonRenderer from ActionColumn
*/
final class ActionColumnRenderer implements ColumnRendererInterface
{
Expand All @@ -23,13 +23,13 @@ final class ActionColumnRenderer implements ColumnRendererInterface
private $defaultUrlCreator;

/**
* @psalm-var array<string,Closure>
* @psalm-var array<string,ButtonRenderer>
*/
private readonly array $defaultButtons;

/**
* @psalm-param UrlCreator|null $defaultUrlCreator
* @psalm-param array<string,Closure> $defaultButtons
* @psalm-param array<string,ButtonRenderer>|null $defaultButtons
*/
public function __construct(
?callable $defaultUrlCreator = null,
Expand Down Expand Up @@ -117,7 +117,7 @@ function (array $matches) use ($column, $buttons, $context): string {
isset($buttons[$name])
) {
$url = $this->createUrl($name, $context);
return (string)$buttons[$name]($url);
return $buttons[$name]($url);
}

return '';
Expand Down