mirror of
https://github.com/flextype/flextype.git
synced 2025-08-06 13:16:45 +02:00
feat(shortcodes): add new shortcodes [uuid1]
[uuid2]
[uuid3]
[uuid4]
This commit is contained in:
60
src/flextype/core/Parsers/Shortcodes/UuidShortcode.php
Normal file
60
src/flextype/core/Parsers/Shortcodes/UuidShortcode.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
|
||||
* and with the full functionality of a traditional CMS!
|
||||
*
|
||||
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
|
||||
*
|
||||
* Licensed under The MIT License.
|
||||
*
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*/
|
||||
|
||||
namespace Flextype\Parsers\Shortcodes;
|
||||
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use function app;
|
||||
use function parsers;
|
||||
use function registry;
|
||||
|
||||
// Shortcode: [uuid1]
|
||||
parsers()->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();
|
||||
});
|
10
tests/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php
Normal file
10
tests/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
test('[uuid1-4] shortcode', function () {
|
||||
expect(strings(parsers()->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();
|
||||
});
|
Reference in New Issue
Block a user