an introduction to php dependency management with composer

29
Composer Dependency Management in PHP Presentation by: Bradley Jacobs / @crazyjaco @crazyjaco

Upload: oomph-inc

Post on 10-May-2015

3.280 views

Category:

Technology


2 download

DESCRIPTION

Bradley Jacob's talk from WordCamp Boston 2013

TRANSCRIPT

Page 1: An Introduction to PHP Dependency Management With Composer

ComposerDependency Management in PHP

Presentation by: Bradley Jacobs / @crazyjaco

@crazyjaco

Page 2: An Introduction to PHP Dependency Management With Composer

Some assumptionsWordPress directory structureJSONWorking with multiple WordPress sites

Page 3: An Introduction to PHP Dependency Management With Composer

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

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

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

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

Why Package/Dependency Management?

Modern day web pages are rarely self-contained.

FrameworksLibrariesScripts

Page 8: An Introduction to PHP Dependency Management With Composer

Dependency Management vsPackage Management

Page 9: An Introduction to PHP Dependency Management With Composer

Introducing Composerhttp://getcomposer.org

Page 10: An Introduction to PHP Dependency Management With Composer

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

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

File acts as both a consumer and provider

composer.json

Schema Documentation

Page 13: An Introduction to PHP Dependency Management With Composer

{ "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

{ "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

Composer.lock

Page 16: An Introduction to PHP Dependency Management With Composer

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

Package RepositoriesWhere do we find and get the packages for composer to install?

Page 18: An Introduction to PHP Dependency Management With Composer

Packagist.orgPackagist.org

Page 19: An Introduction to PHP Dependency Management With Composer

custom installers, WPackagist.org

Using Composer w/WordPress

Page 20: An Introduction to PHP Dependency Management With Composer

WPackagist.org

Page 21: An Introduction to PHP Dependency Management With Composer

-

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

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

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

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

{ "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

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

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

Resources:

Composer Documentationhttp://composer.rarst.net/Trac ticket #23912 - Add composer support to WordPress

Page 29: An Introduction to PHP Dependency Management With Composer

|

Thank You!@crazyjaco github.com/crazyjaco