Extending Composer

Extending Composer

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

1e078b34687f7a685b078ac7b0b02a55?s=128

Till Klampaeckel

October 01, 2013
Tweet

Transcript

  1. www.easybib.com jobs@imagineeasy.com Extending Composer Make composer do all the things.

  2. www.easybib.com jobs@imagineeasy.com Till I’m Till Klampäckel. Good to meet you.

    @klimpong http://github.com/till http://till.klampaeckel.de/
  3. www.easybib.com jobs@imagineeasy.com ImagineEasy Solutions LLC We are an information literacy

    company. What is information literacy?
  4. www.easybib.com jobs@imagineeasy.com Commercial break Some rights reserved by claire.whitehouse http://www.flickr.com/photos/citysnidget/

  5. www.easybib.com jobs@imagineeasy.com 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.
  6. www.easybib.com jobs@imagineeasy.com 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.
  7. www.easybib.com jobs@imagineeasy.com Anyway There is always more. But that’s not

    what I’m here for.
  8. www.easybib.com jobs@imagineeasy.com Composer • Dependency management. • Composer is extendable.

  9. www.easybib.com jobs@imagineeasy.com 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
  10. jobs@imagineeasy.com www.easybib.com You want moar?

  11. www.easybib.com jobs@imagineeasy.com Composer Plugins • From custom installers came plugins.

  12. www.easybib.com jobs@imagineeasy.com 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.
  13. www.easybib.com jobs@imagineeasy.com 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” } }
  14. www.easybib.com jobs@imagineeasy.com 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) { /* ... */ } }
  15. www.easybib.com jobs@imagineeasy.com Composer Plugin Events • Events live in Composer\Plugin\PluginEvents.

    • COMMAND • PRE_FILE_DOWNLOAD
  16. It’s so simple.

  17. www.easybib.com jobs@imagineeasy.com 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
  18. Go write a plugin. Now.

  19. www.easybib.com jobs@imagineeasy.com Don’t forget. Publish code. —

  20. Wait!

  21. www.easybib.com jobs@imagineeasy.com 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
  22. www.easybib.com jobs@imagineeasy.com Questions?