Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
166 lars 1
<?php
2
 
3
namespace Spatie\Sluggable;
4
 
5
class SlugOptions
6
{
7
    /** @var array|callable */
8
    public $generateSlugFrom;
9
 
10
    /** @var callable */
11
    public $extraScopeCallback;
12
 
13
    public string $slugField;
14
 
15
    public bool $generateUniqueSlugs = true;
16
 
17
    public int $maximumLength = 250;
18
 
19
    public bool $skipGenerate = false;
20
 
21
    public bool $generateSlugsOnCreate = true;
22
 
23
    public bool $generateSlugsOnUpdate = true;
24
 
25
    public bool $preventOverwrite = false;
26
 
27
    public string $slugSeparator = '-';
28
 
29
    public string $slugLanguage = 'en';
30
 
31
    public array $translatableLocales = [];
32
 
33
    public int $startSlugSuffixFrom = 1;
34
 
35
    public static function create(): static
36
    {
37
        return new static();
38
    }
39
 
40
    public static function createWithLocales(array $locales): static
41
    {
42
        $slugOptions = static::create();
43
 
44
        $slugOptions->translatableLocales = $locales;
45
 
46
        return $slugOptions;
47
    }
48
 
49
    public function generateSlugsFrom(string | array | callable $fieldName): self
50
    {
51
        if (is_string($fieldName)) {
52
            $fieldName = [$fieldName];
53
        }
54
 
55
        $this->generateSlugFrom = $fieldName;
56
 
57
        return $this;
58
    }
59
 
60
    public function saveSlugsTo(string $fieldName): self
61
    {
62
        $this->slugField = $fieldName;
63
 
64
        return $this;
65
    }
66
 
67
    public function allowDuplicateSlugs(): self
68
    {
69
        $this->generateUniqueSlugs = false;
70
 
71
        return $this;
72
    }
73
 
74
    public function slugsShouldBeNoLongerThan(int $maximumLength): self
75
    {
76
        $this->maximumLength = $maximumLength;
77
 
78
        return $this;
79
    }
80
 
81
    public function skipGenerateWhen(callable $callable): self
82
    {
83
        $this->skipGenerate = $callable() === true;
84
 
85
        return $this;
86
    }
87
 
88
    public function doNotGenerateSlugsOnCreate(): self
89
    {
90
        $this->generateSlugsOnCreate = false;
91
 
92
        return $this;
93
    }
94
 
95
    public function doNotGenerateSlugsOnUpdate(): self
96
    {
97
        $this->generateSlugsOnUpdate = false;
98
 
99
        return $this;
100
    }
101
 
102
    public function preventOverwrite(): self
103
    {
104
        $this->preventOverwrite = true;
105
 
106
        return $this;
107
    }
108
 
109
    public function usingSeparator(string $separator): self
110
    {
111
        $this->slugSeparator = $separator;
112
 
113
        return $this;
114
    }
115
 
116
    public function usingLanguage(string $language): self
117
    {
118
        $this->slugLanguage = $language;
119
 
120
        return $this;
121
    }
122
 
123
    public function extraScope(callable $callbackMethod): self
124
    {
125
        $this->extraScopeCallback = $callbackMethod;
126
 
127
        return $this;
128
    }
129
 
130
    public function startSlugSuffixFrom(int $startSlugSuffixFrom): self
131
    {
132
        $this->startSlugSuffixFrom = max(1, $startSlugSuffixFrom);
133
 
134
        return $this;
135
    }
136
}