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