1 | <?php |
||
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 static function create(): self |
||
25 | { |
||
26 | return new static(); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param string|array|callable $fieldName |
||
31 | * |
||
32 | * @return \Spatie\Sluggable\SlugOptions |
||
33 | */ |
||
34 | public function generateSlugsFrom($fieldName): self |
||
35 | { |
||
36 | if (is_string($fieldName)) { |
||
37 | $fieldName = [$fieldName]; |
||
38 | } |
||
39 | |||
40 | $this->generateSlugFrom = $fieldName; |
||
41 | |||
42 | return $this; |
||
43 | } |
||
44 | |||
45 | public function saveSlugsTo(string $fieldName): self |
||
46 | { |
||
47 | $this->slugField = $fieldName; |
||
48 | |||
49 | return $this; |
||
50 | } |
||
51 | |||
52 | public function allowDuplicateSlugs(): self |
||
53 | { |
||
54 | $this->generateUniqueSlugs = false; |
||
55 | |||
56 | return $this; |
||
57 | } |
||
58 | |||
59 | public function slugsShouldBeNoLongerThan(int $maximumLength): self |
||
60 | { |
||
61 | $this->maximumLength = $maximumLength; |
||
62 | |||
63 | return $this; |
||
64 | } |
||
65 | |||
66 | public function doNotGenerateSlugsOnCreate(): self |
||
67 | { |
||
68 | $this->generateSlugsOnCreate = false; |
||
69 | |||
70 | return $this; |
||
71 | } |
||
72 | |||
73 | public function doNotGenerateSlugsOnUpdate(): self |
||
74 | { |
||
75 | $this->generateSlugsOnUpdate = false; |
||
76 | |||
77 | return $this; |
||
78 | } |
||
79 | |||
80 | public function usingSeparator(string $separator): self |
||
81 | { |
||
82 | $this->slugSeparator = $separator; |
||
83 | |||
84 | return $this; |
||
85 | } |
||
86 | |||
87 | public function usingLanguage(string $language): self |
||
88 | { |
||
89 | $this->slugLanguage = $language; |
||
90 | |||
91 | return $this; |
||
92 | } |
||
93 | } |
||
94 |