Skip to content

Commit

Permalink
Improve Orchestra\Support\Str::searchable() options
Browse files Browse the repository at this point in the history
Signed-off-by: crynobone <[email protected]>
  • Loading branch information
crynobone committed Sep 6, 2013
1 parent e8e29af commit 8b595a1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Orchestra/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ public static function humanize($text)
/**
* Convert basic string to searchable result.
*/
public static function searchable($text)
public static function searchable($text, $wildcard = '*', $replacement = '%')
{
if (static::contains($text, '_') or static::contains($text, '%') return array($text);

return array("{$text}", "{$text}%", "%{$text}", "%{$text}%");
if ( ! static::contains($text, $wildcard))
{
return array(
"{$text}",
"{$text}{$replacement}",
"{$replacement}{$text}",
"{$replacement}{$text}{$replacement}",
);
}

return array(str_replace($wildcard, $replacement, $text));
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ public function testHumanizeSuccessful()
$this->assertEquals($expected, $output);
}

/**
* Test Authorize\Str::searchable() method.
*
* @test
*/
public function testSearchableSuccessful()
{
$expected = array('foobar%');
$output = Str::searchable('foobar*');

$this->assertEquals($expected, $output);

$expected = array('foobar', 'foobar%', '%foobar', '%foobar%');
$output = Str::searchable('foobar');

$this->assertEquals($expected, $output);
}

/**
* Test Orchestra\Support\Str::streamGetContents() method.
*
Expand Down

0 comments on commit 8b595a1

Please sign in to comment.