-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCakeSlugger.php
More file actions
45 lines (39 loc) · 993 Bytes
/
CakeSlugger.php
File metadata and controls
45 lines (39 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Muffin\Slug\Slugger;
use Cake\Utility\Text;
use Muffin\Slug\SluggerInterface;
/**
* CakePHP slugger.
*/
class CakeSlugger implements SluggerInterface
{
/**
* Config options. You can set any valid option which Text::slug() takes
* besides the one listed below:
*
* - `lowercase` - Boolean indication whether slug should be lowercased.
* Defaults to true.
*
* @var array
*/
public $config = [
'lowercase' => true,
];
/**
* Generate slug.
*
* @param string $string Input string.
* @param string $replacement Replacement string.
* @return string Sluggified string.
*/
public function slug($string, $replacement = '-')
{
$config = $this->config;
$config['replacement'] = $replacement;
$string = Text::slug($string, $config);
if ($config['lowercase']) {
return mb_strtolower($string);
}
return $string;
}
}