-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Squirrel\Strings\Filter; | ||
|
||
use Squirrel\Strings\StringFilterInterface; | ||
|
||
/** | ||
* Streamline email format, converting domain part to lowercase and keeping the username part case-sensitive | ||
*/ | ||
class StreamlineEmailFilter implements StringFilterInterface | ||
{ | ||
public function filter(string $string): string | ||
{ | ||
if (\strpos($string, '@') === false) { | ||
return $string; | ||
} | ||
|
||
// Split up email in username and domain part | ||
$emailParts = \explode('@', $string); | ||
|
||
// The first part is always the username part | ||
$username = \array_shift($emailParts); | ||
|
||
// All the other parts are the domain part | ||
$domain = \implode('@', $emailParts); | ||
|
||
$lowercaseFilter = new LowercaseFilter(); | ||
|
||
// Only lowercase the domain part, username can be case sensitive | ||
return $username . '@' . $lowercaseFilter->filter($domain); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
use Squirrel\Strings\Filter\ReplaceUnicodeWhitespacesFilter; | ||
use Squirrel\Strings\Filter\ReplaceUnixStyleNewlinesWithParagraphsAndBreaksFilter; | ||
use Squirrel\Strings\Filter\SnakeCaseToCamelCaseFilter; | ||
use Squirrel\Strings\Filter\StreamlineEmailFilter; | ||
use Squirrel\Strings\Filter\StreamlineInputNoNewlinesFilter; | ||
use Squirrel\Strings\Filter\StreamlineInputWithNewlinesFilter; | ||
use Squirrel\Strings\Filter\TrimFilter; | ||
|
@@ -374,4 +375,22 @@ public function testRemoveHTMLCharacters() | |
{ | ||
$this->assertEquals(" & haha strongmany/strong \xc2\xa0 grüss götter \r\n\n\n\t \n \n invalidl'etat\\ thing contained!!!™ ", (new RemoveHTMLTagCharacters())->filter($this->testString)); | ||
} | ||
|
||
public function testEmailStreamline() | ||
{ | ||
$emails = [ | ||
'bademail' => 'bademail', | ||
'BADEMAIL' => 'BADEMAIL', | ||
'[email protected]' => '[email protected]', | ||
'[email protected]' => '[email protected]', | ||
'[email protected]' => '[email protected]', | ||
'[email protected]' => '[email protected]', | ||
]; | ||
|
||
$emailFilter = new StreamlineEmailFilter(); | ||
|
||
foreach ($emails as $input => $expectedOutput) { | ||
$this->assertSame($expectedOutput, $emailFilter->filter($input)); | ||
} | ||
} | ||
} |