@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * Managers may be instantiated with an array of Shortcodes pre-registered into its library |
| 10 | 10 | */ |
| 11 | 11 | $manager = new ShortcodeManager([ |
| 12 | - 'date' => new SimpleShortcode('date', null, function () { |
|
| 12 | + 'date' => new SimpleShortcode('date', null, function() { |
|
| 13 | 13 | return date('l \t\h\e jS \o\f F, Y'); |
| 14 | 14 | }), |
| 15 | 15 | ]); |
@@ -18,47 +18,47 @@ discard block |
||
| 18 | 18 | * You can chain alias/register/deregister methods |
| 19 | 19 | * This aliases the above [date] tag with [d] |
| 20 | 20 | */ |
| 21 | -echo $manager->alias('date', 'd')->doShortcode('Today is [d]').'<br><br>'; |
|
| 21 | +echo $manager->alias('date', 'd')->doShortcode('Today is [d]') . '<br><br>'; |
|
| 22 | 22 | |
| 23 | 23 | /* |
| 24 | 24 | * You may choose which shortcodes you would like to render |
| 25 | 25 | * */ |
| 26 | -echo $manager->doShortcode('Today is [date], not "[d]"', 'date').'<br><br>'; |
|
| 26 | +echo $manager->doShortcode('Today is [date], not "[d]"', 'date') . '<br><br>'; |
|
| 27 | 27 | |
| 28 | 28 | /* |
| 29 | 29 | * Shortcodes and their aliases can be registered at any time |
| 30 | 30 | * */ |
| 31 | -echo $manager->register(new SimpleShortcode('mail', ['address'=>''], function ($content, $atts) { |
|
| 32 | - return sprintf('<a href="%s">%1$s</a>%s', $atts['address'] ? 'mailto:'.$atts['address'] : '#', $content); |
|
| 33 | -}))->alias('mail', 'm')->doShortcode('[m [email protected]]Test[/m]').'<br><br>'; |
|
| 31 | +echo $manager->register(new SimpleShortcode('mail', ['address'=>''], function($content, $atts) { |
|
| 32 | + return sprintf('<a href="%s">%1$s</a>%s', $atts['address'] ? 'mailto:' . $atts['address'] : '#', $content); |
|
| 33 | +}))->alias('mail', 'm')->doShortcode('[m [email protected]]Test[/m]') . '<br><br>'; |
|
| 34 | 34 | |
| 35 | 35 | /* |
| 36 | 36 | * Nested shortcode can be processed by the Manager |
| 37 | 37 | * You can also decide which tags are available for rendering |
| 38 | 38 | * */ |
| 39 | -echo $manager->register(new SimpleShortcode('nest', null, function ($content) { |
|
| 39 | +echo $manager->register(new SimpleShortcode('nest', null, function($content) { |
|
| 40 | 40 | return $this->manager->doShortcode($content, 'mail'); |
| 41 | -}))->doShortcode('[nest]My email is [mail [email protected]], but "[date]" doesn\'t work[/nest]').'<br><br>'; |
|
| 41 | +}))->doShortcode('[nest]My email is [mail [email protected]], but "[date]" doesn\'t work[/nest]') . '<br><br>'; |
|
| 42 | 42 | |
| 43 | 43 | /* |
| 44 | 44 | * You may also tell the original calling manager to override permissions |
| 45 | 45 | * A third parameter of 'true' will attempt to use the calling manager's tag declarations |
| 46 | 46 | * */ |
| 47 | -echo $manager->doShortcode('[nest]My email is [mail [email protected]], and the date is [d/][/mail][/nest]', 'nest|d', true).'<br><br>'; |
|
| 47 | +echo $manager->doShortcode('[nest]My email is [mail [email protected]], and the date is [d/][/mail][/nest]', 'nest|d', true) . '<br><br>'; |
|
| 48 | 48 | |
| 49 | 49 | /* |
| 50 | 50 | * Let's get rid of 'm' and use it for something else |
| 51 | 51 | * */ |
| 52 | -echo $manager->deregister('m')->register(new SimpleShortcode('m', null, function () { |
|
| 52 | +echo $manager->deregister('m')->register(new SimpleShortcode('m', null, function() { |
|
| 53 | 53 | return 'M is pretty fantastic'; |
| 54 | -}))->doShortcode('My opinion on the letter "M": [m]').'<br><br>'; |
|
| 54 | +}))->doShortcode('My opinion on the letter "M": [m]') . '<br><br>'; |
|
| 55 | 55 | |
| 56 | 56 | /* |
| 57 | 57 | * Let's go even further |
| 58 | 58 | * Let's deregister the original [date] shortcode, but keep its alias |
| 59 | 59 | * The second parameter allows us to prevent deregistration of a given shortcode's aliases |
| 60 | 60 | * */ |
| 61 | -echo $manager->deregister('date', false)->doShortcode('Today is [d], not "[date]"').'<br><br>'; |
|
| 61 | +echo $manager->deregister('date', false)->doShortcode('Today is [d], not "[date]"') . '<br><br>'; |
|
| 62 | 62 | |
| 63 | 63 | /* |
| 64 | 64 | * There are also a few shorthand methods! |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | * There is also a doShortcode method for Shortcode Classes that will allow you to run the manager against only that particular shortcode and its aliases |
| 67 | 67 | * Aliasing is also availble to SimpleShortcode, and Shortcodes that implement AliasInterface |
| 68 | 68 | * */ |
| 69 | -$bold = new SimpleShortcode('bold', null, function ($content) { |
|
| 69 | +$bold = new SimpleShortcode('bold', null, function($content) { |
|
| 70 | 70 | return sprintf('<strong>%s</strong>', $content); |
| 71 | 71 | }); |
| 72 | 72 | $manager[] = $bold; //Shorthand register |
| 73 | 73 | $bold->alias('b'); //Register an alias directly on a shortcode |
| 74 | -echo $bold->doShortcode('[nest][bold]Bold Text[/bold] [b]More Bold Text[/b][/nest]').'<br><br>'; //Run doShortocde directly on a Shortcode and its aliases |
|
| 74 | +echo $bold->doShortcode('[nest][bold]Bold Text[/bold] [b]More Bold Text[/b][/nest]') . '<br><br>'; //Run doShortocde directly on a Shortcode and its aliases |
|
| 75 | 75 | unset($manager['bold']); //Deregister a shortcode and all of its aliases |
| 76 | -echo $bold->doShortcode('[nest][bold]Not so bold text[/bold], [b]or this[/b][/nest]').'<br><br>'; |
|
| 76 | +echo $bold->doShortcode('[nest][bold]Not so bold text[/bold], [b]or this[/b][/nest]') . '<br><br>'; |
|
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | return iterator_to_array($this->generateResults($matches)); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - return preg_replace_callback("/$regex/", function ($match) use ($callback) { |
|
| 34 | + return preg_replace_callback("/$regex/", function($match) use ($callback) { |
|
| 35 | 35 | if ($match[1] == '[' && $match[6] == ']') { |
| 36 | 36 | return substr($match[0], 1, -1); |
| 37 | 37 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | .'\\[\\/\\2\\]' // Closing shortcode tag |
| 83 | 83 | .')?' |
| 84 | 84 | .')' |
| 85 | - .'(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]] |
|
| 85 | + .'(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]] |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | ]); |
| 106 | 106 | $pattern = "/{$patterns}/"; |
| 107 | 107 | $text = preg_replace("/[\x{00a0}\x{200b}]+/u", ' ', $text); |
| 108 | - if (preg_match_all($pattern, (string) $text, $match, PREG_SET_ORDER)) { |
|
| 108 | + if (preg_match_all($pattern, (string)$text, $match, PREG_SET_ORDER)) { |
|
| 109 | 109 | foreach ($match as $m) { |
| 110 | 110 | if (!empty($m[1])) { |
| 111 | 111 | $atts[strtolower($m[1])] = stripcslashes($m[2]); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | public function __construct($name, $atts = [], Closure $callback = null) |
| 42 | 42 | { |
| 43 | 43 | $this->name = $name; |
| 44 | - $this->attributes = (array) $atts; |
|
| 44 | + $this->attributes = (array)$atts; |
|
| 45 | 45 | $this->callback = $callback; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | public function handle(?string $content = null, array $atts = []): string |
| 55 | 55 | { |
| 56 | 56 | if (is_null($this->callback)) { |
| 57 | - return (string) $content; |
|
| 57 | + return (string)$content; |
|
| 58 | 58 | } |
| 59 | 59 | $callback = $this->callback->bindTo($this, $this); |
| 60 | 60 | |
@@ -56,28 +56,28 @@ |
||
| 56 | 56 | private function calculate($units, DateInterval $diff) |
| 57 | 57 | { |
| 58 | 58 | $calculator = [ |
| 59 | - 'centuries' => function (DateInterval $diff) { |
|
| 59 | + 'centuries' => function(DateInterval $diff) { |
|
| 60 | 60 | return $diff->y / 100; |
| 61 | 61 | }, |
| 62 | - 'decades' => function (DateInterval $diff) { |
|
| 62 | + 'decades' => function(DateInterval $diff) { |
|
| 63 | 63 | return $diff->y / 10; |
| 64 | 64 | }, |
| 65 | - 'years' => function (DateInterval $diff) { |
|
| 65 | + 'years' => function(DateInterval $diff) { |
|
| 66 | 66 | return $diff->y; |
| 67 | 67 | }, |
| 68 | - 'months' => function (DateInterval $diff) { |
|
| 68 | + 'months' => function(DateInterval $diff) { |
|
| 69 | 69 | return $diff->y * 12 + $diff->m; |
| 70 | 70 | }, |
| 71 | - 'days' => function (DateInterval $diff) { |
|
| 71 | + 'days' => function(DateInterval $diff) { |
|
| 72 | 72 | return $diff->days; |
| 73 | 73 | }, |
| 74 | - 'hours' => function (DateInterval $diff) { |
|
| 74 | + 'hours' => function(DateInterval $diff) { |
|
| 75 | 75 | return ($diff->days * 24) + $diff->h; |
| 76 | 76 | }, |
| 77 | - 'minutes' => function (DateInterval $diff) { |
|
| 77 | + 'minutes' => function(DateInterval $diff) { |
|
| 78 | 78 | return ($diff->days * 24 * 60) + $diff->i; |
| 79 | 79 | }, |
| 80 | - 'seconds' => function (DateInterval $diff) { |
|
| 80 | + 'seconds' => function(DateInterval $diff) { |
|
| 81 | 81 | return ($diff->days * 24 * 60 * 60) + $diff->s; |
| 82 | 82 | }, |
| 83 | 83 | ]; |
@@ -41,6 +41,6 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | public function handle(?string $content = null): string |
| 43 | 43 | { |
| 44 | - return trim((string) preg_replace('/\s+/', ' ', $this->ipsum)); |
|
| 44 | + return trim((string)preg_replace('/\s+/', ' ', $this->ipsum)); |
|
| 45 | 45 | } |
| 46 | 46 | } |
@@ -141,7 +141,7 @@ |
||
| 141 | 141 | public function doShortcode(string $content, $tags = [], bool $deep = false): string |
| 142 | 142 | { |
| 143 | 143 | $tags = $this->preProcessTags($tags); |
| 144 | - $handler = function (string $tag, ?string $content = null, array $atts = []) { |
|
| 144 | + $handler = function(string $tag, ?string $content = null, array $atts = []) { |
|
| 145 | 145 | $shortcode = $this[$tag]; |
| 146 | 146 | if ($shortcode instanceof AttributeInterface) { |
| 147 | 147 | $atts = array_merge($shortcode->getAttributes(), $atts); |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | /** |
| 18 | 18 | * @const string |
| 19 | 19 | */ |
| 20 | - const NO_ALIAS = 'Cannot alias a shortcode that does not implement '.AliasInterface::class; |
|
| 20 | + const NO_ALIAS = 'Cannot alias a shortcode that does not implement ' . AliasInterface::class; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * @return static |