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

So You Think You Can Composer?

Coen Jacobs
March 29, 2016
40

So You Think You Can Composer?

Coen Jacobs

March 29, 2016
Tweet

Transcript

  1. So You Think You Can Composer? Coen Jacobs - WordPress

    meetup Enschede @CoenJacobs - #wpm053
  2. “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. 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'; require_once 'widgets/widget-show-address.php'; require_once 'widgets/widget-show-map.php'; require_once 'widgets/widget-show-openinghours.php'; require_once 'widgets/widget-storelocator-form.php';
  4. Autoload bonus • Only include files when class is used

    • Includes files from your dependencies • … and files from the dependencies of your dependencies… • … and so on
  5. “You can move the wp-config.php file to the directory above

    your WordPress install. This means for a site installed in the root of your webspace, you can store wp-config.php outside the web-root folder.”
  6. Advantages of Composer • Dependencies declared in a single file

    • Installing and updating handled by a tool • Dependencies locked on specific versions • No third party code in version control
  7. Version control magic • Add all Composer installed directories to

    .gitignore • git clone && composer install
  8. Themes and plugins need to have composer.json, require composer-installers AND

    have their package type set correctly Couple constraints
  9. Plugin dependency conflict • Plugin A bundles version 1.0.0 of

    X • Plugin B bundles version 2.0.0 of X • Versions are not compatible with each other, but can be used at the same time
  10. Downsides to workarounds • Maintenance heavy for updates • Defeats

    purpose of package managers • … but it probably is the only way
  11. Full site management via Composer solves this in 99.9% of

    the cases But it doesn’t help plugin developers…