Composing Project Dependencies

28
Composing Project Dependencies Derek Gallo @derekgallo http://github.com/drock

Transcript of Composing Project Dependencies

Page 1: Composing Project Dependencies

Composing Project Dependencies

Derek Gallo@derekgallo

http://github.com/drock

Page 2: Composing Project Dependencies

Problem

•Projects use many libs or frameworks

•Most libs have several dependencies

•Different projects need different versions

Page 3: Composing Project Dependencies

An Example

PHPUnit 3.7

SymfonyYAML

2.2

PHPUnitMocks

1.3...

Project A

PHPUnit 3.6

SymfonyYAML1.02

PHPUnitMocks

1.1...

Project B

Page 4: Composing Project Dependencies

Pear

PHPUnit 3.7

SymfonyYAML

2.2

PHPUnitMocks

1.3...

Project A Project B

Single shared dependency

No autoloading

Not part of build

Page 5: Composing Project Dependencies

Submodules

PHPUnit 3.7

SymfonyYAML

2.2

PHPUnitMocks

1.3

Project A

PHPUnit 3.6

SymfonyYAML1.02

PHPUnitMocks

1.1

Project B

No autoloading

No dependency management

Page 6: Composing Project Dependencies

Composer!

PHPUnit 3.7

SymfonyYAML

2.2

PHPUnitMocks

1.3...

Project A

PHPUnit 3.6

SymfonyYAML1.02

PHPUnitMocks

1.1...

Project B

Page 7: Composing Project Dependencies

Composer!

•Autoloading

•Dependency Management

•Per project dependencies

•Part of build

Page 8: Composing Project Dependencies

Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

Page 9: Composing Project Dependencies

Installation

•Locally

• curl -sS https://getcomposer.org/installer | php

•Globally

• sudo mv composer.phar /usr/local/bin/composer

• composer selfupdate <- Do regularly

Page 10: Composing Project Dependencies

Silex Sample

•Create empty project folder

•Create composer.json

Page 11: Composing Project Dependencies

Silex Sample

Page 12: Composing Project Dependencies

Silex Sample• >composer install

Page 13: Composing Project Dependencies

Silex Sample• include autoloader

• write controller

Page 14: Composing Project Dependencies

Silex Sample• add monolog

Page 15: Composing Project Dependencies

Silex Sample• >composer update

Page 16: Composing Project Dependencies

Silex Sample• add logging code

Page 17: Composing Project Dependencies

Defining Dependencies

Vendor/Package

Version

Stability Requirements

Page 18: Composing Project Dependencies

Installing Dependencies•>composer install

•downloads dependencies to vendor folder

•generates autoloader

Page 19: Composing Project Dependencies

Using Dependencies

•PSR-0 - Standards defining naming conventions for autoloading.

•Use composer generated autoloader

Page 20: Composing Project Dependencies

Updating Dependencies•>composer update

•upgrades packages to latest version based on rules in composer.json

Page 21: Composing Project Dependencies

Install vs Update•composer.lock

•tracks versions of dependencies used

•commit it

•install-looks for composer.lock then composer.json

•update-looks straight at composer.json and updates composer.lock

Page 22: Composing Project Dependencies

Working in a Team

•Elect a dependency manager

•manages and commits composer files

•add vendor folder to git/svn ignore

Page 23: Composing Project Dependencies

Finding Packages

•Packagist

•>composer search ...

•Github

•look for composer.json

Page 24: Composing Project Dependencies

Older Packages

• Hopefully its PSR-0 compliant

Define a package repository in your

composer.json

Specify locations of sources

Instruct autoloader

Page 25: Composing Project Dependencies

Bleeding EdgeVersion Tag

Version Branch

Other Branch

Page 26: Composing Project Dependencies

Custom Forks• Fork on Github

• Add your repo

• Specify your branch

Page 27: Composing Project Dependencies

Bootstrapping>composer create-project -s dev fabpot/silex-skeleton .