1 | <?php |
||
15 | trait Slugger |
||
16 | { |
||
17 | /** |
||
18 | * @var array List of attributes to automatically generate unique URL names (slugs) for. |
||
19 | * |
||
20 | * protected $slugs = []; |
||
21 | */ |
||
22 | protected $slugs = []; |
||
23 | |||
24 | /** |
||
25 | * Boot the sluggable trait for a model. |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | public static function bootSlugger() |
||
45 | |||
46 | /** |
||
47 | * Adds slug attributes to the dataset, used before saving. |
||
48 | * |
||
49 | * @return void |
||
50 | */ |
||
51 | public function slugAttributes() |
||
57 | |||
58 | /** |
||
59 | * Sets a single slug attribute value. |
||
60 | * |
||
61 | * @param string $slugAttribute Attribute to populate with the slug. |
||
62 | * @param mixed $sourceAttributes Attribute(s) to generate the slug from. |
||
63 | * Supports dotted notation for relations. |
||
64 | * @param int $maxLength Maximum length for the slug not including the counter. |
||
65 | * |
||
66 | * @return string The generated value. |
||
67 | */ |
||
68 | public function setSluggedValue($slugAttribute, $sourceAttributes, $maxLength = 240) |
||
89 | |||
90 | /** |
||
91 | * Ensures a unique attribute value, if the value is already used a counter suffix is added. |
||
92 | * |
||
93 | * @param string $name The database column name. |
||
94 | * @param value $value The desired column value. |
||
95 | * |
||
96 | * @return string A safe value that is unique. |
||
97 | */ |
||
98 | protected function getSluggableUniqueAttributeValue($name, $value) |
||
113 | |||
114 | /** |
||
115 | * Get an attribute relation value using dotted notation. |
||
116 | * Eg: author.name. |
||
117 | * |
||
118 | * @return mixed |
||
119 | */ |
||
120 | protected function getSluggableSourceAttributeValue($key) |
||
138 | |||
139 | /** |
||
140 | * Override the default slug separator. |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | public function getSluggableSeparator() |
||
148 | } |
||
149 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.