1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 01:16:52 +02:00

Merge pull request #1975 from flarum/fl/194-better-slugs

Use Laravel's slugger for basic transliteration
This commit is contained in:
Franz Liedke
2020-01-31 13:32:55 +01:00
committed by GitHub
4 changed files with 6 additions and 33 deletions

View File

@@ -23,7 +23,7 @@ use Flarum\Notification\Notification;
use Flarum\Post\MergeableInterface;
use Flarum\Post\Post;
use Flarum\User\User;
use Flarum\Util\Str;
use Illuminate\Support\Str;
/**
* @property int $id

View File

@@ -1,31 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Util;
class Str
{
/**
* Create a slug out of the given string.
*
* Non-alphanumeric characters are converted to hyphens.
*
* @param string $str
* @return string
*/
public static function slug($str)
{
$str = strtolower($str);
$str = preg_replace('/[^a-z0-9]/i', '-', $str);
$str = preg_replace('/-+/', '-', $str);
$str = preg_replace('/-$|^-/', '', $str);
return $str;
}
}