Skip to content

Commit 4241c69

Browse files
authored
Merge pull request #146 from ralphjsmit/main
Make `->setExactActive()` accept a callable as well
2 parents 678e0ed + 8080307 commit 4241c69

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/Traits/Activatable.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public function isActive(): bool
2222
public function setActive(bool | callable $active = true): static
2323
{
2424
if (is_callable($active)) {
25-
$this->active = $active($this);
26-
27-
return $this;
25+
$active = (bool)$active($this);
2826
}
2927

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

7472
/**
7573
* Set if current Activatable should be marked as an exact url match.
76-
*
77-
* @param bool $exactActive
78-
*
79-
* @return $this
8074
*/
81-
public function setExactActive(bool $exactActive = true): static
75+
public function setExactActive(bool | callable $exactActive = true): static
8276
{
77+
if (is_callable($exactActive)) {
78+
$this->exactActive = $exactActive($this);
79+
80+
return $this;
81+
}
82+
8383
$this->exactActive = $exactActive;
8484

8585
return $this;

tests/Traits/ActivatableTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@
2626
return false;
2727
})->isActive())->toBeFalse();
2828
});
29+
30+
it('can be set exact active via a callable', function () {
31+
expect($this->activatable->setExactActive(function () {
32+
return false;
33+
})->isExactActive())->toBeFalse();
34+
});

0 commit comments

Comments
 (0)