From 9245f26dd2ec12ebb14787c909c3270029555b77 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 8 May 2022 07:34:10 +0300 Subject: [PATCH] feat(shortcodes): add new shortcodes `[uuid1]` `[uuid2]` `[uuid3]` `[uuid4]` --- .../core/Parsers/Shortcodes/UuidShortcode.php | 60 +++++++++++++++++++ .../core/Parsers/Shortcodes/UuidShortcode.php | 10 ++++ 2 files changed, 70 insertions(+) create mode 100644 src/flextype/core/Parsers/Shortcodes/UuidShortcode.php create mode 100644 tests/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php diff --git a/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php b/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php new file mode 100644 index 00000000..9d3fa929 --- /dev/null +++ b/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php @@ -0,0 +1,60 @@ +shortcodes()->addHandler('uuid1', static function () { + if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.uuid.enabled')) { + return ''; + } + + return Uuid::uuid1()->toString(); +}); + +// Shortcode: [uuid2] +parsers()->shortcodes()->addHandler('uuid2', static function () { + if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.uuid.enabled')) { + return ''; + } + + return Uuid::uuid2()->toString(); +}); + +// Shortcode: [uuid3] +parsers()->shortcodes()->addHandler('uuid3', static function () { + if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.uuid.enabled')) { + return ''; + } + + return Uuid::uuid3()->toString(); +}); + + +// Shortcode: [uuid4] +parsers()->shortcodes()->addHandler('uuid4', static function () { + if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.uuid.enabled')) { + return ''; + } + + return Uuid::uuid4()->toString(); +}); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php b/tests/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php new file mode 100644 index 00000000..931b0a91 --- /dev/null +++ b/tests/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php @@ -0,0 +1,10 @@ +shortcodes()->parse('[uuid1]'))->length() > 0)->toBeTrue(); + expect(strings(parsers()->shortcodes()->parse('[uuid2]'))->length() > 0)->toBeTrue(); + expect(strings(parsers()->shortcodes()->parse('[uuid3]'))->length() > 0)->toBeTrue(); + expect(strings(parsers()->shortcodes()->parse('[uuid4]'))->length() > 0)->toBeTrue(); +}); \ No newline at end of file