PHP Reinvented
How Composer helped shape the new way of writing PHP

About Me

Free Software Developer
  https://github.com/naderman

phpBB Development Lead
  https://www.phpbb.com

Composer Co-Author
  https://getcomposer.org

Professional Managed phpBB Hosting & Consulting around PHP & Composer
  https://www.forumatic.com

Why should you care?

“When people are incompetent in the strategies they adopt to achieve success and satisfaction, they suffer a dual burden: Not only do they reach erroneous conclusions and make unfortunate choices, but their incompetence robs them of the ability to realize it. Instead, like Mr. Wheeler, they are left with the erroneous impression they are doing just fine.”

Dunning Kruger Effect

http://opinionator.blogs.nytimes.com/2010/06/20/the-anosognosics-dilemma-1

Congratulations, you are here to learn about what you have yet to learn.

Buzzwords

Empty shells or indicative of important changes?

Ephemeralization

“the ability of technological advancement to do ‘more and more with less and less until eventually you can do everything with nothing’.”

Wikipedia

Automation isn't just for factories

... and it's not just for big clusters either

Package and Dependency Management elsewhere

Early 2011

phpBB Plugins

Symfony Bundles

Composer

The Composer Ecosystem

github.com/composer

The Composer Ecosystem

Composer - CLI Tool

The Composer Ecosystem

Packagist - Package Repository

The Composer Ecosystem

Satis - Micro Repository

The Composer Ecosystem

composer/installers

Custom Package Installers for

  • MediaWiki
  • OXID
  • phpBB
  • PPI
  • SilverStripe
  • Symfony1
  • TYPO3 Flow
  • Wordpress
  • Zend Framework
  • CakePHP
  • CodeIgniter
  • Drupal
  • FuelPHP
  • Joomla!
  • Kohana
  • Laravel
  • Lithium
  • Magento

Usage Instructions

Using a project

git clone https://github.com/symfony/standard-edition myproject
            
Cloning into myproject...
cd myproject/
            
curl -s http://getcomposer.org/installer | php
            
All settings correct for using Composer Composer successfully installed to: /home/bob/myproject/composer.phar Use it: php composer.phar

Using a project

php composer.phar install
            
Installing from lock file - Package twig/extensions (dev-master) Downloading Unpacking archive Cleaning up [...] - Package twig/twig (1.8.0) Downloading Unpacking archive Cleaning up - Package symfony/symfony (dev-master) Downloading Unpacking archive Cleaning up Generating autoload files

Using a project

vendor/
    autoload.php
    composer/
    monolog/
        monolog/
    symfony/
        symfony/
        monolog-bundle/
    twig/
        twig/
        extensions/
    [...]
            

Downloading Project Dependencies

composer.json

{
    "require": {
        "silex/silex": ">=1.0.0-dev",
        "symfony/finder": "2.1-dev",
        "twig/twig": "1.*",
        "predis/service-provider": "dev-master"
        "symfony/console": "~2.1"
    },
    "require-dev": {
        "mikey179/vfsStream": "*"
    }
}
            

Avoiding version chaos
in your team

composer.lock


Benefits

Autoloading

Libraries/projects define their namespaces:

"autoload": {
    "psr-0": {
        "Vendor\\Namespace": "lib/"
    },
    "classmap": ["src/", "VeryOld.php"]
},
"include-path": ["src/", ""]
            

Composer builds an autoloader for you:

vendor/autoload.php
                

Use the generated autoloader:

require __DIR__.'/../vendor/autoload.php';

use Silex\Application;
use Silex\Extension\TwigExtension;

use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\Response;

$app = new Application();
// ...