1
0
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:
Awilum
2022-05-08 07:34:10 +03:00
parent 85d8a620cf
commit 9245f26dd2
2 changed files with 70 additions and 0 deletions

View 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();
});

View 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();
});