Skip to content

Commit

Permalink
RatingComponent: add options
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed Feb 19, 2023
1 parent eb0e672 commit c2412b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Rating/RatingComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ final class RatingComponent extends Control

private int $increase = 0;

/**
* @param array<string, mixed> $options
*/
public function __construct(
private RatingModelInterface $model,
private Rating $rating,
private array $options = [],
)
{
}
Expand Down Expand Up @@ -51,6 +55,10 @@ public function render(mixed ... $arguments): void
$template->increase = $this->increase;
$template->canVote = $this->rating->canVote();

foreach ($this->options as $name => $value) {
$template->$name = $value;
}

foreach ($arguments as $name => $value) {
$template->$name = $value;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Rating/RatingComponentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
interface RatingComponentFactory
{

public function create(RatingModelInterface $model, Rating $rating): RatingComponent;
/**
* @param array<string, mixed> $options
*/
public function create(RatingModelInterface $model, Rating $rating, array $options = []): RatingComponent;

}

0 comments on commit c2412b2

Please sign in to comment.