1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Sluggable; |
4
|
|
|
|
5
|
|
|
class SlugOptions |
6
|
|
|
{ |
7
|
|
|
/** @var array|callable */ |
8
|
|
|
public $generateSlugFrom; |
9
|
|
|
|
10
|
|
|
public string $slugField; |
|
|
|
|
11
|
|
|
|
12
|
|
|
public bool $generateUniqueSlugs = true; |
13
|
|
|
|
14
|
|
|
public int $maximumLength = 250; |
15
|
|
|
|
16
|
|
|
public bool $generateSlugsOnCreate = true; |
17
|
|
|
|
18
|
|
|
public bool $generateSlugsOnUpdate = true; |
19
|
|
|
|
20
|
|
|
public string $slugSeparator = '-'; |
21
|
|
|
|
22
|
|
|
public string $slugLanguage = 'en'; |
23
|
|
|
|
24
|
|
|
public array $translatableLocales = []; |
25
|
|
|
|
26
|
|
|
public static function create(): self |
27
|
|
|
{ |
28
|
|
|
return new static(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public static function createWithLocales(array $locales): self |
32
|
|
|
{ |
33
|
|
|
$slugOptions = static::create(); |
34
|
|
|
|
35
|
|
|
$slugOptions->translatableLocales = $locales; |
36
|
|
|
|
37
|
|
|
return $slugOptions; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string|array|callable $fieldName |
42
|
|
|
* |
43
|
|
|
* @return \Spatie\Sluggable\SlugOptions |
44
|
|
|
*/ |
45
|
|
|
public function generateSlugsFrom($fieldName): self |
46
|
|
|
{ |
47
|
|
|
if (is_string($fieldName)) { |
48
|
|
|
$fieldName = [$fieldName]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->generateSlugFrom = $fieldName; |
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function saveSlugsTo(string $fieldName): self |
57
|
|
|
{ |
58
|
|
|
$this->slugField = $fieldName; |
59
|
|
|
|
60
|
|
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function allowDuplicateSlugs(): self |
64
|
|
|
{ |
65
|
|
|
$this->generateUniqueSlugs = false; |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function slugsShouldBeNoLongerThan(int $maximumLength): self |
71
|
|
|
{ |
72
|
|
|
$this->maximumLength = $maximumLength; |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function doNotGenerateSlugsOnCreate(): self |
78
|
|
|
{ |
79
|
|
|
$this->generateSlugsOnCreate = false; |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function doNotGenerateSlugsOnUpdate(): self |
85
|
|
|
{ |
86
|
|
|
$this->generateSlugsOnUpdate = false; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function usingSeparator(string $separator): self |
92
|
|
|
{ |
93
|
|
|
$this->slugSeparator = $separator; |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function usingLanguage(string $language): self |
99
|
|
|
{ |
100
|
|
|
$this->slugLanguage = $language; |
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|