Exemplo n.º 1
0
 public function testAliasedShortcode()
 {
     $manager = new ShortcodeManager();
     $test = new Library\SimpleShortcode('test', null, function () {
         return 'test';
     });
     $manager['test'] = $test;
     $manager->alias('test', 't');
     $this->assertEquals($test->doShortcode('[test/][t/]'), 'testtest');
     $this->assertEquals($manager->doShortcode('[test/][t/]'), 'testtest');
     $manager->deregister('test');
     $this->assertEmpty($manager->getRegistered());
 }
Exemplo n.º 2
0
<?php

require '../bootstrap/autoload.php';
use Maiorano\Shortcodes\Manager\ShortcodeManager;
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) {
Exemplo n.º 3
0
 /**
  * @expectedException \Maiorano\Shortcodes\Exceptions\RegisterException
  * @expectedExceptionMessage No shortcode with identifier 'test' has been registered
  */
 public function testAliasMissing()
 {
     $manager = new ShortcodeManager();
     $manager->alias('test', 't');
 }