Laravelista\Ekko\Ekko::isActiveMatch PHP Method

isActiveMatch() public method

Detects if the given string is found in the current URL.
public isActiveMatch ( string $string, string $output = "active" ) : boolean
$string string
$output string
return boolean
    public function isActiveMatch($string, $output = "active")
    {
        if (strpos($this->url->current(), $string) !== false) {
            return $output;
        }
        return null;
    }

Usage Example

Example #1
0
 /** @test */
 public function it_detects_active_match_in_url()
 {
     $router = m::mock(\Illuminate\Routing\Router::class);
     $url = m::mock(\Illuminate\Routing\UrlGenerator::class);
     $url->shouldReceive('current')->times(4)->andReturn('/somewhere-over-the-rainbow');
     $ekko = new Ekko($router, $url);
     $this->assertEquals("active", $ekko->isActiveMatch('over-the-rainbow'));
     $this->assertEquals("hello", $ekko->isActiveMatch('over-the-rainbow', "hello"));
     $this->assertEquals(null, $ekko->isActiveMatch('under-the-rainbow'));
     $this->assertEquals(null, $ekko->isActiveMatch('under-the-rainbow', 'hello'));
 }