@@ -53,7 +53,7 @@ |
||
| 53 | 53 | public function doShortcode($content, $tags = [], $deep = false) |
| 54 | 54 | { |
| 55 | 55 | $tags = $this->preProcessTags($tags); |
| 56 | - $content = $this->parser->parseShortcode($content, $tags, function ($tag, $content, $atts) { |
|
| 56 | + $content = $this->parser->parseShortcode($content, $tags, function($tag, $content, $atts) { |
|
| 57 | 57 | |
| 58 | 58 | $shortcode = $this[$tag]; |
| 59 | 59 | if ($shortcode instanceof AttributeInterface) { |
@@ -53,28 +53,28 @@ |
||
| 53 | 53 | private function calculate($units, DateInterval $diff) |
| 54 | 54 | { |
| 55 | 55 | $calculator = [ |
| 56 | - 'centuries' => function (DateInterval $diff) { |
|
| 56 | + 'centuries' => function(DateInterval $diff) { |
|
| 57 | 57 | return $diff->y / 100; |
| 58 | 58 | }, |
| 59 | - 'decades' => function (DateInterval $diff) { |
|
| 59 | + 'decades' => function(DateInterval $diff) { |
|
| 60 | 60 | return $diff->y / 10; |
| 61 | 61 | }, |
| 62 | - 'years' => function (DateInterval $diff) { |
|
| 62 | + 'years' => function(DateInterval $diff) { |
|
| 63 | 63 | return $diff->y; |
| 64 | 64 | }, |
| 65 | - 'months' => function (DateInterval $diff) { |
|
| 65 | + 'months' => function(DateInterval $diff) { |
|
| 66 | 66 | return $diff->y * 12 + $diff->m; |
| 67 | 67 | }, |
| 68 | - 'days' => function (DateInterval $diff) { |
|
| 68 | + 'days' => function(DateInterval $diff) { |
|
| 69 | 69 | return $diff->days + $diff->d; |
| 70 | 70 | }, |
| 71 | - 'hours' => function (DateInterval $diff) { |
|
| 71 | + 'hours' => function(DateInterval $diff) { |
|
| 72 | 72 | return ($diff->days * 24) + $diff->h; |
| 73 | 73 | }, |
| 74 | - 'minutes' => function (DateInterval $diff) { |
|
| 74 | + 'minutes' => function(DateInterval $diff) { |
|
| 75 | 75 | return ($diff->days * 24 * 60) + $diff->i; |
| 76 | 76 | }, |
| 77 | - 'seconds' => function (DateInterval $diff) { |
|
| 77 | + 'seconds' => function(DateInterval $diff) { |
|
| 78 | 78 | return ($diff->days * 24 * 60 * 60) + $diff->s; |
| 79 | 79 | } |
| 80 | 80 | ]; |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | return $results; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - return preg_replace_callback("/$regex/", function ($match) use ($callback) { |
|
| 43 | + return preg_replace_callback("/$regex/", function($match) use ($callback) { |
|
| 44 | 44 | if ($match[1] == '[' && $match[6] == ']') { |
| 45 | 45 | return substr($match[0], 1, -1); |
| 46 | 46 | } |
@@ -118,6 +118,6 @@ discard block |
||
| 118 | 118 | . '\\[\\/\\2\\]' // Closing shortcode tag |
| 119 | 119 | . ')?' |
| 120 | 120 | . ')' |
| 121 | - . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]] |
|
| 121 | + . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]] |
|
| 122 | 122 | } |
| 123 | 123 | } |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function addPrefix($prefix, $baseDir) |
| 33 | 33 | { |
| 34 | - $prefix = trim($prefix, '\\').'\\'; |
|
| 35 | - $baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; |
|
| 34 | + $prefix = trim($prefix, '\\') . '\\'; |
|
| 35 | + $baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
|
| 36 | 36 | $this->prefixes[] = array($prefix, $baseDir); |
| 37 | 37 | } |
| 38 | 38 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | list($currentPrefix, $currentBaseDir) = $current; |
| 50 | 50 | if (0 === strpos($class, $currentPrefix)) { |
| 51 | 51 | $classWithoutPrefix = substr($class, strlen($currentPrefix)); |
| 52 | - $file = $currentBaseDir.str_replace('\\', DIRECTORY_SEPARATOR, $classWithoutPrefix).'.php'; |
|
| 52 | + $file = $currentBaseDir . str_replace('\\', DIRECTORY_SEPARATOR, $classWithoutPrefix) . '.php'; |
|
| 53 | 53 | if (file_exists($file)) { |
| 54 | 54 | return $file; |
| 55 | 55 | } |
@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | use Symfony\Component\ClassLoader\Psr4ClassLoader; |
| 3 | 3 | |
| 4 | -if(file_exists(__DIR__.'/../vendor/autoload.php')){ |
|
| 5 | - require(__DIR__.'/../vendor/autoload.php'); |
|
| 4 | +if (file_exists(__DIR__ . '/../vendor/autoload.php')) { |
|
| 5 | + require(__DIR__ . '/../vendor/autoload.php'); |
|
| 6 | 6 | } |
| 7 | -else{ |
|
| 8 | - require __DIR__.'/../lib/ClassLoader/Psr4ClassLoader.php'; |
|
| 7 | +else { |
|
| 8 | + require __DIR__ . '/../lib/ClassLoader/Psr4ClassLoader.php'; |
|
| 9 | 9 | |
| 10 | 10 | $loader = new Psr4ClassLoader(); |
| 11 | - $loader->addPrefix('Maiorano\\Shortcodes\\', __DIR__.'/../src'); |
|
| 11 | + $loader->addPrefix('Maiorano\\Shortcodes\\', __DIR__ . '/../src'); |
|
| 12 | 12 | $loader->register(); |
| 13 | 13 | } |
@@ -3,8 +3,7 @@ |
||
| 3 | 3 | |
| 4 | 4 | if(file_exists(__DIR__.'/../vendor/autoload.php')){ |
| 5 | 5 | require(__DIR__.'/../vendor/autoload.php'); |
| 6 | -} |
|
| 7 | -else{ |
|
| 6 | +} else{ |
|
| 8 | 7 | require __DIR__.'/../lib/ClassLoader/Psr4ClassLoader.php'; |
| 9 | 8 | |
| 10 | 9 | $loader = new Psr4ClassLoader(); |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * Managers may be instantiated with an array of Shortcodes pre-registered into its library |
| 9 | 9 | */ |
| 10 | 10 | $manager = new ShortcodeManager([ |
| 11 | - 'date' => new SimpleShortcode('date', null, function () { |
|
| 11 | + 'date' => new SimpleShortcode('date', null, function() { |
|
| 12 | 12 | return date('l \t\h\e jS \o\f F, Y'); |
| 13 | 13 | }) |
| 14 | 14 | ]); |
@@ -17,47 +17,47 @@ discard block |
||
| 17 | 17 | * You can chain alias/register/deregister methods |
| 18 | 18 | * This aliases the above [date] tag with [d] |
| 19 | 19 | */ |
| 20 | -echo $manager->alias('date', 'd')->doShortcode('Today is [d]').'<br><br>'; |
|
| 20 | +echo $manager->alias('date', 'd')->doShortcode('Today is [d]') . '<br><br>'; |
|
| 21 | 21 | |
| 22 | 22 | /* |
| 23 | 23 | * You may choose which shortcodes you would like to render |
| 24 | 24 | * */ |
| 25 | -echo $manager->doShortcode('Today is [date], not "[d]"', 'date').'<br><br>'; |
|
| 25 | +echo $manager->doShortcode('Today is [date], not "[d]"', 'date') . '<br><br>'; |
|
| 26 | 26 | |
| 27 | 27 | /* |
| 28 | 28 | * Shortcodes and their aliases can be registered at any time |
| 29 | 29 | * */ |
| 30 | -echo $manager->register(new SimpleShortcode('mail', ['address'=>''], function($content, $atts){ |
|
| 31 | - return sprintf('<a href="%s">%1$s</a>%s', $atts['address'] ? 'mailto:'.$atts['address'] : '#', $content); |
|
| 32 | -}))->alias('mail', 'm')->doShortcode('[m [email protected]]Test[/m]').'<br><br>'; |
|
| 30 | +echo $manager->register(new SimpleShortcode('mail', ['address'=>''], function($content, $atts) { |
|
| 31 | + return sprintf('<a href="%s">%1$s</a>%s', $atts['address'] ? 'mailto:' . $atts['address'] : '#', $content); |
|
| 32 | +}))->alias('mail', 'm')->doShortcode('[m [email protected]]Test[/m]') . '<br><br>'; |
|
| 33 | 33 | |
| 34 | 34 | /* |
| 35 | 35 | * Nested shortcode can be processed by the Manager |
| 36 | 36 | * You can also decide which tags are available for rendering |
| 37 | 37 | * */ |
| 38 | -echo $manager->register(new SimpleShortcode('nest', null, function ($content) { |
|
| 38 | +echo $manager->register(new SimpleShortcode('nest', null, function($content) { |
|
| 39 | 39 | return $this->manager->doShortcode($content, 'mail'); |
| 40 | -}))->doShortcode('[nest]My email is [mail [email protected]], but "[date]" doesn\'t work[/nest]').'<br><br>'; |
|
| 40 | +}))->doShortcode('[nest]My email is [mail [email protected]], but "[date]" doesn\'t work[/nest]') . '<br><br>'; |
|
| 41 | 41 | |
| 42 | 42 | /* |
| 43 | 43 | * You may also tell the original calling manager to override permissions |
| 44 | 44 | * A third parameter of 'true' will attempt to use the calling manager's tag declarations |
| 45 | 45 | * */ |
| 46 | -echo $manager->doShortcode('[nest]My email is [mail [email protected]], and the date is [d/][/mail][/nest]', 'nest|d', true).'<br><br>'; |
|
| 46 | +echo $manager->doShortcode('[nest]My email is [mail [email protected]], and the date is [d/][/mail][/nest]', 'nest|d', true) . '<br><br>'; |
|
| 47 | 47 | |
| 48 | 48 | /* |
| 49 | 49 | * Let's get rid of 'm' and use it for something else |
| 50 | 50 | * */ |
| 51 | -echo $manager->deregister('m')->register(new SimpleShortcode('m', null, function(){ |
|
| 51 | +echo $manager->deregister('m')->register(new SimpleShortcode('m', null, function() { |
|
| 52 | 52 | return 'M is pretty fantastic'; |
| 53 | -}))->doShortcode('My opinion on the letter "M": [m]').'<br><br>'; |
|
| 53 | +}))->doShortcode('My opinion on the letter "M": [m]') . '<br><br>'; |
|
| 54 | 54 | |
| 55 | 55 | /* |
| 56 | 56 | * Let's go even further |
| 57 | 57 | * Let's deregister the original [date] shortcode, but keep its alias |
| 58 | 58 | * The second parameter allows us to prevent deregistration of a given shortcode's aliases |
| 59 | 59 | * */ |
| 60 | -echo $manager->deregister('date', false)->doShortcode('Today is [d], not "[date]"').'<br><br>'; |
|
| 60 | +echo $manager->deregister('date', false)->doShortcode('Today is [d], not "[date]"') . '<br><br>'; |
|
| 61 | 61 | |
| 62 | 62 | /* |
| 63 | 63 | * There are also a few shorthand methods! |
@@ -65,11 +65,11 @@ discard block |
||
| 65 | 65 | * 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 |
| 66 | 66 | * Aliasing is also availble to SimpleShortcode, and Shortcodes that implement AliasInterface |
| 67 | 67 | * */ |
| 68 | -$bold = new SimpleShortcode('bold', null, function($content){ |
|
| 68 | +$bold = new SimpleShortcode('bold', null, function($content) { |
|
| 69 | 69 | return sprintf('<strong>%s</strong>', $content); |
| 70 | 70 | }); |
| 71 | 71 | $manager[] = $bold; //Shorthand register |
| 72 | 72 | $bold->alias('b'); //Register an alias directly on a shortcode |
| 73 | -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 |
|
| 73 | +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 | 74 | unset($manager['bold']); //Deregister a shortcode and all of its aliases |
| 75 | -echo $bold->doShortcode('[nest][bold]Not so bold text[/bold], [b]or this[/b][/nest]').'<br><br>'; |
|
| 75 | +echo $bold->doShortcode('[nest][bold]Not so bold text[/bold], [b]or this[/b][/nest]') . '<br><br>'; |
|