Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Love-Hate Relationship Between Composer and...

Coen Jacobs
September 26, 2015

The Love-Hate Relationship Between Composer and WordPress (WordCamp Netherlands 2015)

Coen Jacobs

September 26, 2015
Tweet

More Decks by Coen Jacobs

Other Decks in Programming

Transcript

  1. Hello My name is Coen Jacobs Developer at Radish Concepts

    Jumped out of the bubble Still do WordPress projects
  2. Composer “Composer is a tool for dependency management in PHP.

    It allows you to declare the libraries your project depends on and it will manage (install/ update) them for you.”
  3. What does Composer do? » Load your dependencies » Loads

    dependencies of your dependencies » And so on... » Offers a powerful autoloader » Inspired by npm and bundler » Made by Jordi Boggiano
  4. Manual loading... require_once 'classes/class-core.php'; require_once 'includes/wpseo-local-functions.php'; require_once 'includes/ajax-functions.php'; require_once 'classes/class-core.php';

    require_once 'classes/class-admin.php'; require_once 'classes/class-admin-wrappers.php'; require_once 'classes/class-metaboxes.php'; require_once 'classes/class-frontend.php'; require_once 'classes/class-storelocator.php'; require_once 'classes/class-taxonomy.php';
  5. Classmap: "autoload": { "classmap": [ "includes" ] } PSR-4: "autoload":

    { "psr-4": {"Never5\\ WPNotificationCenter\\": "src/"} }
  6. Plugin A: "require": { "wpupdatephp/wp-update-php": "~1.0" } Plugin B: "require":

    { "wpupdatephp/wp-update-php": "~1.0" } Solution: Install WPupdatePHP version 1.0.0, right?
  7. In the example, 1.0.0 was loaded the plugin bundling 1.1.0,

    assumes that version is there Fatal error: Call to undefined method
  8. What if you can't? Want to bundle something with your

    plugin What if you can't add your site to Composer?
  9. Creates a master composer.json » loop through wp-content/plugins/ » check

    for composer.json file » run wikimedia/composer-merge-plugin » composer install » installed in wp-content/vendor/ At least in theory, this works
  10. Thank you! @CoenJacobs coenjacobs.me Want to work with me? We're

    looking for both frontend & backend developers! Contact me or @radishconcepts
  11. Image credit » Slide 1: https://www.flickr.com/photos/ lizadaly/4373330774/ » Slide 7:

    https://www.flickr.com/photos/ diaper/7328032558/ » Slide 13: https://www.flickr.com/ photos/93277085@N08/12715023064/ » Slide 15: https://www.flickr.com/ photos/dandeluca/2720139047/ » Slide 22: https://www.flickr.com/ photos/usnavy/7879793204/
  12. Image credit » Slide 27: https://www.flickr.com/ photos/mdpettitt/4954174041/ » Slide 30:

    https://www.flickr.com/ photos/orphanjones/1769903155/ » Slide 36: https://www.flickr.com/ photos/twitteroffice/4524716820/ » Slide 43: https://www.flickr.com/ photos/doug88888/4537134655/