From afec6f1103542a73748b6352021c9c232c81cb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sat, 6 May 2023 23:46:31 +0200 Subject: [PATCH] add class that handles model with slug --- src/PersistentData/Model/ModelWithSlug.php | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/PersistentData/Model/ModelWithSlug.php 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()); + } +}