thunderer / Shortcode

Advanced shortcode (BBCode) parser and engine for PHP
http://kowalczyk.cc
MIT License
378 stars 29 forks source link

Is it possible to use this without composer? #97

Closed mark8044 closed 3 years ago

mark8044 commented 3 years ago

Really need a BBCode parser and glad to have found this one that looks actively supported? But I have no way of using composer. Any easy way to still use this?

Thanks!!

thunderer commented 3 years ago

Hi @mark8044, thanks for the kind words - yes, the library is stable and actively maintained. It would be great if you used Composer, but if you really can't, you can always download the library code and put it into your project directly.

mark8044 commented 3 years ago

Hi @mark8044, thanks for the kind words - yes, the library is stable and actively maintained. It would be great if you used Composer, but if you really can't, you can always download the library code and put it into your project directly.

Thats great to hear! Do you have an example of how I could use it?

I tried the following but its a total fail:

    require_once(DIR . '/myincludes/shortcode/ShortcodeFacade.php');
    use \Shortcode\ShortcodeFacade;
    use \Shortcode\Shortcode\ShortcodeInterface;

    $facade = new ShortcodeFacade();
    $facade->addHandler('hello', function(ShortcodeInterface $s) {
        return sprintf('Hello, %s!', $s->getParameter('name'));
    });

    $text = '
        <div class="user">[hello name="Thomas"]</div>
        <p>Your shortcodes are very good, keep it up!</p>
        <div class="user">[hello name="Peter"]</div>
    ';
    echo $facade->process($text);
jdreesen commented 3 years ago

You probably have to manually require each (used) class/file or implement some sort of autoloader for this library yourself.

thunderer commented 3 years ago

@mark8044 yes, @jdreesen is right - one of the (loads of) benefits of Composer is that you get an autoloader for free. If you want to use the library without it, you need to autoload classes yourself, either by manually require()ing the files or registering your own autoloader through spl_autoload_register().

You can't just load the ShortcodeFacade because it requires other classes, but you're pretty close - please either make your own autoloader or just keep loading the missing classes manually.

...or you can use Composer and get the autoloader and all of the other goodies for free. :smile: The choice is yours!

thunderer commented 3 years ago

@mark8044 I'm closing this issue as we've answered your question. Feel free to open another one if there is anything else we can help you with.