diff --git a/src/PersistentData/Model/ModelWithSlug.php b/src/PersistentData/Model/ModelWithSlug.php new file mode 100644 index 0000000..337b869 --- /dev/null +++ b/src/PersistentData/Model/ModelWithSlug.php @@ -0,0 +1,35 @@ +slug = $slug; + } + + public function getSlug(): string + { + if ($this->slug === null) { + $this->slug = $this->generateSlug(); + } + + return $this->slug; + } + + private function generateSlug(): string + { + $slugSourceGetMethod = 'get' . str_replace('_', '', ucwords(static::$slugSource, '_')); + return Slugify::create()->slugify($this->$slugSourceGetMethod()); + } +}