1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 13:16:45 +02:00

feat(shortcodes): add ability to use php directive with php shortcode

This commit is contained in:
Awilum
2022-05-27 16:46:24 +03:00
parent 5fe6c9a13e
commit 9274fb42b1
2 changed files with 21 additions and 7 deletions

View File

@@ -24,8 +24,12 @@ parsers()->shortcodes()->addHandler('php', static function (ShortcodeInterface $
if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.php.enabled')) {
return '';
}
ob_start();
eval($s->getContent());
return ob_get_clean();
if ($s->getContent() != null) {
ob_start();
eval($s->getContent());
return ob_get_clean();
}
return '@php';
});

View File

@@ -2,7 +2,17 @@
declare(strict_types=1);
test('[php] shortcode', function () {
$this->assertEquals("Foo",
parsers()->shortcodes()->parse('(php)echo "Foo";(/php)'));
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->ensureExists(0755, true);
});
afterEach(function () {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('php shortcode', function () {
$this->assertEquals("Foo", parsers()->shortcodes()->parse('(php)echo "Foo";(/php)'));
expect(entries()->create('bar', ['test' => '(php) echo "Bar";']))->toBeTrue();
expect(entries()->fetch('bar')['test'])->toBe('Bar');
});