Ejemplo n.º 1
0
use Maiorano\Shortcodes\Library\SimpleShortcode;
/*
 * Managers may be instantiated with an array of Shortcodes pre-registered into its library
 */
$manager = new ShortcodeManager(['date' => new SimpleShortcode('date', null, function () {
    return date('l \\t\\h\\e jS \\o\\f F, Y');
})]);
/*
 * You can chain alias/register/deregister methods
 * This aliases the above [date] tag with [d]
 */
echo $manager->alias('date', 'd')->doShortcode('Today is [d]') . '<br><br>';
/*
 * You may choose which shortcodes you would like to render
 * */
echo $manager->doShortcode('Today is [date], not "[d]"', 'date') . '<br><br>';
/*
 * Shortcodes and their aliases can be registered at any time
 * */
echo $manager->register(new SimpleShortcode('mail', ['address' => ''], function ($content, $atts) {
    return sprintf('<a href="%s">%1$s</a>%s', $atts['address'] ? 'mailto:' . $atts['address'] : '#', $content);
}))->alias('mail', 'm')->doShortcode('[m address=test@test.com]Test[/m]') . '<br><br>';
/*
 * Nested shortcode can be processed by the Manager
 * You can also decide which tags are available for rendering
 * */
echo $manager->register(new SimpleShortcode('nest', null, function ($content) {
    return $this->manager->doShortcode($content, 'mail');
}))->doShortcode('[nest]My email is [mail address=test@test.com], but "[date]" doesn\'t work[/nest]') . '<br><br>';
/*
 * You may also tell the original calling manager to override permissions
Ejemplo n.º 2
0
 public function testShorthand()
 {
     $manager = new ShortcodeManager();
     $test = new Library\SimpleShortcode('test', null, function () {
         return 'test';
     });
     $test->alias('t');
     $manager[] = $test;
     $this->assertEquals($test->doShortcode('[test/][t/]'), 'testtest');
     $this->assertEquals($manager->doShortcode('[test/][t/]'), 'testtest');
 }