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();
// ...
                

Evolution of PHP

Goals

Methods

New frameworks

Symfony2, Laravel, Silex, Lithium ...

Single purpose libraries

Assetic, Guzzle, Monolog, Twig, Imagine, ...

Faster innovation cycle

Packagist Growth

PHP Language Evolution

Closures (PHP 5.3)

$x = $request->query->get('x', 0);
$addX = function($a) use ($x) { return $a+$b; }
$newNumbers = array_map($addX, $numbers);
                

Short array syntax (PHP 5.4)

$a = [1, 3, 5, 9];
                

PHP Language Evolution

Generators (PHP 5.5)

function xrange($start, $limit, $step = 1) {
    for ($i = $start; $i <= $limit; $i += $step) {
        yield $i;
    }
}
foreach (xrange(1, 9, 2) as $number) {
    echo "$number ";
}
                

Many more smaller changes & more to come

HHVM & Hack (?)

Drupal8 composer.json Pt 1

"name": "drupal/drupal",
"description": "Drupal is an open source content management platform powering millions of websites and applications.",
"type": "drupal-core",
"license": "GPL-2.0+",
"autoload": {
  "psr-0": {
    "Drupal\\Core": "core/lib/",
    "Drupal\\Component": "core/lib/",
    "Drupal\\Driver": "drivers/lib/"
  },
  "files": [
    "core/lib/Drupal.php"
  ]
},
"config": {
  "vendor-dir": "core/vendor",
  "preferred-install": "dist",
  "autoloader-suffix": "Drupal8"
}
          

Drupal8 composer.json Pt 2

"require": {
  "php": ">=5.4.2",
  "sdboyer/gliph": "0.1.*",
  "symfony/class-loader": "2.4.*",
  "symfony/dependency-injection": "2.4.*",
  "symfony/event-dispatcher": "2.4.*",
  "symfony/http-foundation": "2.4.*",
  "symfony/http-kernel": "2.4.*",
  "symfony/routing": "2.4.*",
  "symfony/serializer": "2.4.*",
  "symfony/validator": "2.4.*",
  "symfony/yaml": "dev-master#e49a47d60348665261f6e279ba383241deb73cab",
  "twig/twig": "1.15.*",
  "doctrine/common": "dev-master#a45d110f71c323e29f41eb0696fa230e3fa1b1b5",
  "doctrine/annotations": "dev-master#463d926a8dcc49271cb7db5a08364a70ed6e3cd3",
  "guzzlehttp/guzzle": "4.0.*",
  "kriswallsmith/assetic": "1.1.*@alpha",
  "symfony-cmf/routing": "1.1.*@alpha",
  "easyrdf/easyrdf": "0.8.*",
  "phpunit/phpunit": "3.7.*",
  "zendframework/zend-feed": "2.2.*"
},
          

Look around.

Write small libs.

Share code.

Reuse things.

Reinvigorate PHP

Find Out More

Thank you.

Questions?

@naderman