Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tutorial Using Composer with PocketMine

Comments in 'Resources' started by Falk, Dec 24, 2014.

  1. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    This tutorial assumes that you know what composer is and have it installed on your system. You can go to http://getcomposer.org for information.

    Miner is still a beta program and bugs should be labelled as "features". If that label won't stick please report it at https://github.com/Falkirks/Miner/issues

    Composer 2014-12-23 21-28-56.png
    The problem
    Composer is great. But it just won't play well with PocketMine for a few reasons:
    • The "/vendor" directory contradicts PocketMine plugin development standards
    • Registering an additional autoloader for composer is messy and impractical. Also it could interfere with the PocketMine one. Also the classes wouldn't be accessible from AsyncTasks because that autoloaders need to be registered again on the worker threads.
    • Adding "/vendor" to the PocketMien autoloader would work but would not be standards and would cause issues if PocketMine needed to remove your plugin from the loader.
    The solution
    Miner
    . Miner is composer wrapper which behaves like composer. Just run Miner instead of composer and Miner will do directory prep, execute composer and then port the composer autoloaders into your "/src" directory. This will work for most psr-0 and psr-4 autoloaders, it can even fix some autoloaders which wouldn't work on a simple copy-paste.

    demo.gif

    How?
    • Get composer installed as one of the following
      • composer (in your $PATH)
      • composer.phar (in your home directory)
      • composer.phar (in plugin directory)
    • Go to https://github.com/Falkirks/Miner/releases/latest and download the phar build. Put it somewhere that is easy to access on your computer.
    • Open a terminal and cd to your plugin directory with a composer.json
    • Run php /path/to/Miner.phar
      • You should see something similar to what is shown above.
      • Now try running php /path/to/Miner.phar install
      • This will install dependencies and move them to you "/src"
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Why no stub #/usr/ENV/bin php?
  3. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    That would be useful. Didn't think to do that at the time. I am just executing the PHAR file directly with PHP, so a stub like that never was really needed in my build process. If you want to PR, go ahead.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    But it has the side effect of an extra line of STDOUT, which may not be so attractive. (It has to be before <?php)

Share This Page

Advertisement