Refactored code to comply with PSR-*
Signed-off-by: Gergely POLONKAI <polesz@w00d5t0ck.info>
This commit is contained in:
@@ -4,30 +4,40 @@ namespace KekRozsak\FrontBundle\Extensions;
|
||||
|
||||
class Slugifier
|
||||
{
|
||||
/**
|
||||
* Slugify string
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public function slugify($text)
|
||||
{
|
||||
$text = trim(preg_replace('~[^\\pL\d]+~u', '-', $text));
|
||||
/**
|
||||
* Slugify string
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public function slugify($text)
|
||||
{
|
||||
$text = preg_replace(
|
||||
'~[^-\w]+~',
|
||||
'',
|
||||
str_replace(
|
||||
array('"', "'", ':'),
|
||||
'',
|
||||
strtolower(
|
||||
iconv(
|
||||
'utf-8',
|
||||
'us-ascii//TRANSLIT',
|
||||
trim(
|
||||
preg_replace(
|
||||
'~[^\\pL\d]+~u',
|
||||
'-',
|
||||
$text
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if (function_exists('iconv'))
|
||||
{
|
||||
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
|
||||
}
|
||||
if (empty($text)) {
|
||||
$text = 'n-a';
|
||||
}
|
||||
|
||||
$text = strtolower($text);
|
||||
|
||||
$text = preg_replace('~[^-\w]+~', '', $text);
|
||||
|
||||
if (empty($text))
|
||||
{
|
||||
$text = 'n-a';
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user