| 1 | <?php namespace Webwizo\Shortcodes; |
||
| 5 | class Shortcode |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Shortcode compiler |
||
| 9 | * |
||
| 10 | * @var \Webwizo\Shortcodes\Compilers\ShortcodeCompiler |
||
| 11 | */ |
||
| 12 | protected $compiler; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Constructor |
||
| 16 | * |
||
| 17 | * @param \Webwizo\Shortcodes\Compilers\ShortcodeCompiler $compiler |
||
| 18 | */ |
||
| 19 | public function __construct(ShortcodeCompiler $compiler) |
||
| 20 | { |
||
| 21 | $this->compiler = $compiler; |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Register a new shortcode |
||
| 26 | * |
||
| 27 | * @param string $name |
||
| 28 | * @param callable|string $callback |
||
| 29 | * |
||
| 30 | * @return \Webwizo\Shortcodes\Shortcode |
||
| 31 | */ |
||
| 32 | public function register($name, $callback) |
||
| 33 | { |
||
| 34 | $this->compiler->add($name, $callback); |
||
| 35 | |||
| 36 | return $this; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Enable the laravel-shortcodes |
||
| 41 | * |
||
| 42 | * @return \Webwizo\Shortcodes\Shortcode |
||
| 43 | */ |
||
| 44 | public function enable() |
||
| 45 | { |
||
| 46 | $this->compiler->enable(); |
||
| 47 | |||
| 48 | return $this; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Disable the laravel-shortcodes |
||
| 53 | * |
||
| 54 | * @return \Webwizo\Shortcodes\Shortcode |
||
| 55 | */ |
||
| 56 | public function disable() |
||
| 57 | { |
||
| 58 | $this->compiler->disable(); |
||
| 59 | |||
| 60 | return $this; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Compile the given string |
||
| 65 | * |
||
| 66 | * @param string $value |
||
| 67 | * |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | public function compile($value) |
||
| 71 | { |
||
| 72 | // Always enable when we call the compile method directly |
||
| 73 | $this->enable(); |
||
| 74 | |||
| 75 | // return compiled contents |
||
| 76 | return $this->compiler->compile($value); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Remove all shortcode tags from the given content. |
||
| 81 | * |
||
| 82 | * @param string $value |
||
| 83 | * |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | public function strip($value) |
||
| 90 | } |
||
| 91 |