From 96cb06452d58321234685582f5b371a1e44181d5 Mon Sep 17 00:00:00 2001 From: Abdellah Ramadan Date: Thu, 24 Apr 2025 23:18:55 +0100 Subject: [PATCH] - Prefix and Suffix for Slug - Uuid tests - Ip tests - Authored tests - TimeStamped tests --- CHANGELOG.md | 8 ++++++++ README.md | 8 ++++++++ docs/slug.md | 2 ++ src/Common/Attributes/Slugged.php | 2 ++ src/EventListener/Authored/AuthoredListener.php | 2 +- src/EventListener/Slugged/SluggedListener.php | 8 ++++++++ tests/bootstrap.php | 0 7 files changed, 29 insertions(+), 1 deletion(-) delete mode 100644 tests/bootstrap.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b55fdc..e09fb0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## [0.1.6] - 2025-04-24 +### Added +- Prefix and Suffix for Slug +- Uuid tests +- Ip tests +- Authored tests +- TimeStamped tests + ## [0.1.5] - 2025-04-19 ### Added - UUID \ No newline at end of file diff --git a/README.md b/README.md index 5319924..13c856b 100644 --- a/README.md +++ b/README.md @@ -25,3 +25,11 @@ Open a command console, enter your project directory and execute: composer require rami/entity-kit-bundle ``` +Test += + +```console +./vendor/bin/phpunit +``` + +check the `tests` directory \ No newline at end of file diff --git a/docs/slug.md b/docs/slug.md index 10d1f04..de26aa5 100644 --- a/docs/slug.md +++ b/docs/slug.md @@ -23,4 +23,6 @@ fields: [] // An array of fields the entity has for slug generation ensureUnique: true // True by default. if a slug exists, it appends an incremental number at the end separator: '-' // defaults to '-' shouldRegenerateOnUpdate: false // False by default +prefix: string // beginning of the slug +suffix: string // ending of the slug ``` \ No newline at end of file diff --git a/src/Common/Attributes/Slugged.php b/src/Common/Attributes/Slugged.php index 90b0a78..250a503 100644 --- a/src/Common/Attributes/Slugged.php +++ b/src/Common/Attributes/Slugged.php @@ -7,6 +7,8 @@ class Slugged { public function __construct( public ?array $fields = [], + public ?string $prefix = null, + public ?string $suffix = null, public bool $ensureUnique = true, public string $separator = '-', public bool $shouldRegenerateOnUpdate = false diff --git a/src/EventListener/Authored/AuthoredListener.php b/src/EventListener/Authored/AuthoredListener.php index 1073dcf..66a5428 100644 --- a/src/EventListener/Authored/AuthoredListener.php +++ b/src/EventListener/Authored/AuthoredListener.php @@ -58,7 +58,7 @@ private function getCurrentUserIdentifier(): string|null return null; } - $user = $this->tokenStorage->getToken()->getUser(); + $user = $this->tokenStorage?->getToken()?->getUser(); if (!$user instanceof UserInterface) { return null; diff --git a/src/EventListener/Slugged/SluggedListener.php b/src/EventListener/Slugged/SluggedListener.php index 4a9dc4d..1d75bae 100644 --- a/src/EventListener/Slugged/SluggedListener.php +++ b/src/EventListener/Slugged/SluggedListener.php @@ -88,6 +88,14 @@ private function applySlug($entity): void $slugger = new AsciiSlugger(); + if (null !== $attributes->prefix) { + $slugFied = $attributes->prefix . ' ' . $slugFied; + } + + if (null !== $attributes->suffix) { + $slugFied = $slugFied . ' ' . $attributes->suffix; + } + $slugFied = $slugger->slug($slugFied, $separator)->lower(); if (true === $attributes->ensureUnique) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index e69de29..0000000