![Page 1: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/1.jpg)
ComposerDependency Management in PHP
Presentation by: Bradley Jacobs / @crazyjaco
@crazyjaco
![Page 2: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/2.jpg)
Some assumptionsWordPress directory structureJSONWorking with multiple WordPress sites
![Page 3: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/3.jpg)
Talking PointsGoalsWhat is Dependency ManagementIntroduction to Composer
The composer.json fileThe composer.lock fileAuto-loading
Package RepositoriesUsing Composer with WordPressWrap up Demo
![Page 4: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/4.jpg)
Getting to a better workflow through Composer
Goal:Rapidly create a WordPress server setup that can be replicated
quickly and consistently
TLDR;
![Page 5: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/5.jpg)
WordPress Skeletonhttps://github.com/markjaquith/WordPress-Skeleton
./wp/ ./wp/wp-admin/ ./wp/wp-content/ ./wp/wp-includes/./wp-content/./index.html./wp-config.php
![Page 6: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/6.jpg)
Dependency/PackageManagement
What is a package?
A package is just a bunch of files in a folder
Dependencies are a type of package.
![Page 7: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/7.jpg)
Why Package/Dependency Management?
Modern day web pages are rarely self-contained.
FrameworksLibrariesScripts
![Page 8: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/8.jpg)
Dependency Management vsPackage Management
![Page 10: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/10.jpg)
Demo 1 - PHPUnit{ "name": "crazyjaco/phpunit-test", "description": "A test of using composer with phpunit", "license": "proprietary", "require": { "phpunit/phpunit":"3.7.*" }}
![Page 11: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/11.jpg)
Download and run the Composer-Setup.exe
Installation
Mac/Linux
$ curl -sS https://getcomposer.org/installer | php$ mv composer.phar /usr/local/bin/composer
Windows:
![Page 12: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/12.jpg)
File acts as both a consumer and provider
composer.json
Schema Documentation
![Page 13: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/13.jpg)
{ "name": "bradley/mycoolproject", "description": "This project does cool stuff", "keywords": ["wordcamp", "boston", "cool"], "homepage": "http://github.com/crazyjaco/mycoolproject", "type": "library", "license": "MIT", "authors": [ { "name": "Bradley Jacobs", "email": "[email protected]", "homepage": "http://oomphinc.com" } ], "repositories":{ "type": "composer", "url": "http://custom-repo.org" }, "require": { "oomph/framework": "3.2", "bigcompany/api-library": ">4.0" }, "require-dev": { "custom-repo/unit-tester": "2.3.*", "logger/logger": "1.7.*", "debug/tools": "~2.0" }, "suggest": { "coolcompany/extension": "Allow extension to the core program" }}
![Page 14: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/14.jpg)
{ "name": "bradley/mycoolproject", "description": "This project does cool stuff", "keywords": ["wordcamp", "boston", "cool"], "homepage": "http://github.com/crazyjaco/mycoolproject", "type": "library", "license": "MIT", "authors": [ { "name": "Bradley Jacobs", "email": "[email protected]", "homepage": "http://oomphinc.com" } ], "repositories":{ "type": "composer", "url": "http://custom-repo.org" }, "require": {
![Page 15: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/15.jpg)
Composer.lock
![Page 16: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/16.jpg)
This one line gives you access to all of the classes in yourdependencies.
Autoloading*** All dependencies are loaded into the '/vendor' folder ***
require 'vendor/autoload.php';
![Page 17: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/17.jpg)
Package RepositoriesWhere do we find and get the packages for composer to install?
![Page 19: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/19.jpg)
custom installers, WPackagist.org
Using Composer w/WordPress
![Page 21: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/21.jpg)
-
Custom InstallersIt will be necessary for additional actions on occasion, like
installing something outside the /vendor folder.
http://composer.github.io/installers/ An installer for packagesthat need special installation based on package type
![Page 22: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/22.jpg)
Hosted Plugin
{ "name": "oomphinc/coolplugin", "type": "wordpress-plugin", "require": { "composer/installers": "*" }}
Your Project{ "name": "crazyjaco/wordpress-composer-test", "description": "A test of using composer with WordPress", "license": "proprietary", "repositories": [ { "type": "composer", "url": "http://wpackagist.org" } ], "require": { "wpackagist/yet-another-related-posts-plugin":"*", "wpackagist/wp-super-cache":"*", "wpackagist/jetpack":"*" }, "require-dev": { "wpackagist/developer":"*" }}
![Page 23: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/23.jpg)
Demo 2Using the Custom Installer for WordPress Plugins
{ "name": "crazyjaco/wordpress-composer-test", "description": "A test of using composer with WordPress", "license": "proprietary", "repositories": [ { "type": "composer", "url": "http://wpackagist.org" } ], "require": { "wpackagist/yet-another-related-posts-plugin":"*", "wpackagist/wp-super-cache":"*", "wpackagist/jetpack":"*" }, "require-dev": { "wpackagist/developer":"*" }}
![Page 24: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/24.jpg)
Goal: Generate the WordPress Skeleton
Final Demo - WordPress Endgame
./wp/ ./wp/wp-admin/ ./wp/wp-content/ ./wp/wp-includes/./wp-content/./index.html./wp-config.php
![Page 25: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/25.jpg)
{ "name": "crazyjaco/wp-full-demo", "description": "Full WordPress Install Demo", "keywords": ["WordPress", "theme", "plugin", "Oomph"], "homepage": "http://oomphinc.com/", "type": "project", "license": "proprietary", "authors": [ { "name": "Bradley Jacobs - Oomph", "email": "[email protected]", "homepage": "http://oomphinc.com" } ], "repositories": [ { "type": "composer", "url": "http://wpackagist.org" }, {
![Page 26: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/26.jpg)
Where do we go from hereIntegration of Source Control (SVN, Git, Hg)Pre/Post install hooksWP-CLI commands
![Page 27: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/27.jpg)
Wrapping UpGoalsWhat is Dependency ManagementIntroduction to Composer
The composer.json fileThe composer.lock fileAuto-loading
Package RepositoriesUsing Composer with WordPressWrap up Demo
![Page 28: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/28.jpg)
Resources:
Composer Documentationhttp://composer.rarst.net/Trac ticket #23912 - Add composer support to WordPress
![Page 29: An Introduction to PHP Dependency Management With Composer](https://reader035.vdocuments.mx/reader035/viewer/2022062312/554f5ec8b4c905bb178b459c/html5/thumbnails/29.jpg)
|
Thank You!@crazyjaco github.com/crazyjaco