$30 off During Our Annual Pro Sale. View Details »

Extending Composer

Extending Composer

A talk I gave at the October meetup of the PHP Usergroup in Berlin.

Till Klampaeckel

October 01, 2013
Tweet

More Decks by Till Klampaeckel

Other Decks in Technology

Transcript

  1. www.easybib.com [email protected]
    Extending Composer
    Make composer do all the things.

    View Slide

  2. www.easybib.com [email protected]
    Till
    I’m Till Klampäckel. Good to meet you.
    @klimpong
    http://github.com/till
    http://till.klampaeckel.de/

    View Slide

  3. www.easybib.com [email protected]
    ImagineEasy Solutions LLC
    We are an information literacy company.
    What is information literacy?

    View Slide

  4. www.easybib.com [email protected]
    Commercial break
    Some rights reserved by claire.whitehouse
    http://www.flickr.com/photos/citysnidget/

    View Slide

  5. www.easybib.com [email protected]
    EasyBib.com
    EasyBib is an citation management platform. 40 million students use EasyBib every year.
    Over 1000 institutions subscribe, including 100 large US universities and 900 high schools
    and districts.

    View Slide

  6. www.easybib.com [email protected]
    ResearchReady.com
    ResearchReady teaches information literacy skills in a core curriculum. Universities and
    districts subscribe to give their students a research skill boost. Launched in January 2013.

    View Slide

  7. www.easybib.com [email protected]
    Anyway
    There is always more.
    But that’s not what I’m here for.

    View Slide

  8. www.easybib.com [email protected]
    Composer
    • Dependency management.
    • Composer is extendable.

    View Slide

  9. www.easybib.com [email protected]
    Extending Composer
    • In the beginning, there were custom installers.
    • Some examples:
    • custom installers for frameworks
    • custom installers for software
    • custom installers for assets and related

    View Slide

  10. [email protected]
    www.easybib.com
    You want moar?

    View Slide

  11. www.easybib.com [email protected]
    Composer Plugins
    • From custom installers came plugins.

    View Slide

  12. www.easybib.com [email protected]
    Some very gut advice
    • Open source project management pro tip!
    • Add a plugin API so you don’t need to maintain
    what users are doing.
    • Second pro tip: don’t break the plugin API.

    View Slide

  13. www.easybib.com [email protected]
    Composer Plugins
    {
    “name”: “till/fancy-plugin”,
    “license”: “BSD-2-Clause”,
    “type”: “composer-plugin”,
    “require”: {
    “composer-plugin-api”: “1.0.0”
    },
    “extra”: {
    “class”: “till\\Composer\\ExamplePlugin”
    }
    }

    View Slide

  14. www.easybib.com [email protected]
    Composer Plugins
    namespace till\Composer;
    use Composer\Composer, Composer\IO\IOInterface,
    Composer\Plugin\PluginInterface, Composer\Plugin\PluginEvents,
    Composer\Plugin\CommandEvent;
    class ExamplePlugin implements PluginInterface
    {
    protected $c, $io;
    public function activate(Composer $c, IOInterface $io) {
    $this->c = $c; $this->io = $io;
    }
    public static function getSubcribedEvents() {
    return array(PluginEvents::COMMAND => array(array(‘onCommand’, 0)));
    }
    public function onCommand(CommandEvent $e) {
    /* ... */
    }
    }

    View Slide

  15. www.easybib.com [email protected]
    Composer Plugin Events
    • Events live in Composer\Plugin\PluginEvents.
    • COMMAND
    • PRE_FILE_DOWNLOAD

    View Slide

  16. It’s so simple.

    View Slide

  17. www.easybib.com [email protected]
    Wait, just two?
    • Currently two events are available.
    • If you need another event, let’s add it.
    • Example implementations
    • composer-aws:
    https://github.com/naderman/composer-aws
    • composer-newrelic:
    https://github.com/easybiblabs/composer-newrelic

    View Slide

  18. Go write a plugin. Now.

    View Slide

  19. www.easybib.com [email protected]
    Don’t forget.
    Publish code. —

    View Slide

  20. Wait!

    View Slide

  21. www.easybib.com [email protected]
    Global
    • `./composer.phar global install|update|require`
    • I don’t want to talk about it too much:
    http://getcomposer.org/doc/03-cli.md#global
    • Install plugins globally:
    ./composer.phar global require till/fancy-plugin:dev-master

    View Slide

  22. www.easybib.com [email protected]
    Questions?

    View Slide