Skip to content

Commit

Permalink
Merge pull request #146 from ralphjsmit/main
Browse files Browse the repository at this point in the history
Make `->setExactActive()` accept a callable as well
  • Loading branch information
freekmurze authored Apr 12, 2023
2 parents 678e0ed + 8080307 commit 4241c69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Traits/Activatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public function isActive(): bool
public function setActive(bool | callable $active = true): static
{
if (is_callable($active)) {
$this->active = $active($this);

return $this;
$active = (bool)$active($this);
}

$this->active = $active;
Expand Down Expand Up @@ -73,13 +71,15 @@ public function determineActiveForUrl(string $url, string $root = '/'): void

/**
* Set if current Activatable should be marked as an exact url match.
*
* @param bool $exactActive
*
* @return $this
*/
public function setExactActive(bool $exactActive = true): static
public function setExactActive(bool | callable $exactActive = true): static
{
if (is_callable($exactActive)) {
$this->exactActive = $exactActive($this);

return $this;
}

$this->exactActive = $exactActive;

return $this;
Expand Down
6 changes: 6 additions & 0 deletions tests/Traits/ActivatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@
return false;
})->isActive())->toBeFalse();
});

it('can be set exact active via a callable', function () {
expect($this->activatable->setExactActive(function () {
return false;
})->isExactActive())->toBeFalse();
});

0 comments on commit 4241c69

Please sign in to comment.