Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The Love-Hate Relationship Between Composer and...
Search
Coen Jacobs
September 26, 2015
Programming
250
0
Share
The Love-Hate Relationship Between Composer and WordPress (WordCamp Netherlands 2015)
Coen Jacobs
September 26, 2015
More Decks by Coen Jacobs
See All by Coen Jacobs
So You Think You Can Composer?
coenjacobs
0
52
State of WordPress and eCommerce (WordPress meetup Nijmegen september 2015)
coenjacobs
0
370
Other Decks in Programming
See All in Programming
PHPでバイナリをパースして理解するASN.1
muno92
PRO
0
470
開発体験を左右するライブラリの API 設計 - GraphQL スキーマ構築ライブラリから考える #tskaigi
izumin5210
2
460
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
630
Agent Skills を社内で育てる仕組み作り
jackchuka
1
2.3k
PHPでローカル環境用のSSL/TLS証明書を発行することはできるのか? #phpconkagawa
akase244
0
380
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
120
権限チェックの一貫性を型で守る TypeScript による多層防御
mnch
3
500
Agentic UI beyond Chats Architecture Patterns & Open Standards @ngMunich 05/2026
manfredsteyer
PRO
0
130
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
4
520
「OSSがあるなら自作するな」は AI時代も正しいか ── Build vs Adopt の新しい判断基準
kumorn5s
7
2.9k
UaaL×Androidアプリのメモリ計測 — Memory Profilerの先へ
rio432
0
170
AI駆動開発で崩れていくコードベースを立て直す
kyoko_nr_nr
1
320
Featured
See All Featured
Six Lessons from altMBA
skipperchong
29
4.2k
HDC tutorial
michielstock
2
670
GitHub's CSS Performance
jonrohan
1033
470k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
510
We Are The Robots
honzajavorek
0
230
Being A Developer After 40
akosma
91
590k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
WCS-LA-2024
lcolladotor
0
600
AI: The stuff that nobody shows you
jnunemaker
PRO
7
650
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
180
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
460
Git: the NoSQL Database
bkeepers
PRO
432
67k
Transcript
The Love-Hate Relationship Between Composer and WordPress @CoenJacobs at #wcnl
2015
Hello My name is Coen Jacobs Developer at Radish Concepts
Jumped out of the bubble Still do WordPress projects
Outside of the WordPress ecosystem, fun stuff happens too!
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.”
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
Alright, but how does it work?
Autoloading
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';
Classmap: "autoload": { "classmap": [ "includes" ] } PSR-4: "autoload":
{ "psr-4": {"Never5\\ WPNotificationCenter\\": "src/"} }
Just add require 'vendor/autoload.php'; That's it Does this for dependencies
as well
Even PHP 5.2 compatible
All plugins should use Composer autoloading, seriously! (if you have
more than one file)
Nothing but love so far!
Trust me, we'll get to the good stuff soon!
Dependency management
Say, you have a fancy library or want to use
one
Add it to your composer.json "require": { "wpupdatephp/wp-update-php": "~1.0" }
run composer install
Package will be installed vendor/wpupdatephp/ wp-update-php/ Added to autoloader as
well
And one day... (actually, two days ago...)
Dependency hell
You'll have this problem with any dependency manager That includes:
doing it manually
What's wrong?
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?
Sadly, no... Users download zip files, with vendor directory bundled
Bundling is the only way
One plugin bundles 1.1.0, the other 1.0.0 Which one is
used?
The race is on!
Include the file or the autoloader autoloader does class_exists check
first one wins
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
Now the fun stuff begins!
What can we do to prevent this?
Prefix everything!
Example: Pimple Pimple: namespace Pimple; Danny's prefixed version: namespace ScrollTriggeredBoxes\DI;
It works But where is the developer happiness?
Every update of Pimple... Update all the files Someone make
a SaaS for this...
How would a developer solve this?
Manage the entire site via Composer Including WordPress core Everything
works fine, at least 99% of the time
What if you can't? Want to bundle something with your
plugin What if you can't add your site to Composer?
well...
Add Composer to your site
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
In WordPress core? Maybe Requires PHP 5.3+ Fairly resource intensive
The only proper solution
Until that day...
Thank you! @CoenJacobs coenjacobs.me Want to work with me? We're
looking for both frontend & backend developers! Contact me or @radishconcepts
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/
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/