On Github Crell / slides-php-pie
Presented by Larry Garfield (@Crell)
We have too much code
in the world
— "No Silver Bullet", 1986.
Commercial Off The Shelf (COTS)
— "'No Silver Bullet', Refired", 1995.
Hey, look, Open Source!
The way to be more productive is to write less code
The way to be more productive is to reuse more code
— Van Snyder, JPLas quoted in "'No Silver Bullet', Refired", 1995.
Sharing must be easy or it won't happen
Sharing is how Open Source works
Sucking at sharing is howOpen Source dies
PHP sucked at sharing
This is my island
There are many like it, but this one is mine
2% of the web cares
3% of the web cares
18% of the web cares
Who cares?
This was the best we could do
NIH is normal
80% of the web cares
Source: W3Techs— Urban legend statistics
Sharing is how Open Source works
Sucking at sharing is howOpen Source dies
PHP is 18 years old
and is finally growing up
First version
function __autoload($class) { $file = some_logic($class); include $file; }
Useful version
spl_autoload_register('myproject_autoloader'); function myproject_autoloader($class) { $file = some_logic($class); include $file; }
— Every PHP developer circa 2007
I can't use PHP 5, no hosts support it.—Developers
I can't upgrade to PHP 5, no projects require it.—Hosts
We can't drop support for PHP 4, all the hosts still use it.—PHP Internals
We can't be the first to use PHP 5, we'll lose our users.—PHP projects
We've decided that we will all be first.
Epic. Win.
Build software better, together
Better than Sourceforge et al by a wide margin.
2013: PHP leads GitHub
class Zend_Form {} class Application_Form_Guestbook extends Zend_Form {} class sfForm() {}
Oh PEAR...
class Structures_DataGrid_DataSource_CSV {} class Structures_DataGrid_DataSource_CSV_Memory extends Structures_DataGrid_DataSource_CSV {}
namespace Zend\Form; class Factory{}
namespace Zend\Form; use Zend\Captcha; $factory = new Factory(); $captcha = new Captcha();
namespace Zend\Form; use Zend\Captcha; use Guzzle\Http\Client; $factory = new Factory(); $captcha = new Captcha(); $guzzle = new Client();
(Smoke not guaranteed)
<vendor>\Package\Whatever
new \Some\Class\Name_Here();
include_once $some_root . '/Some/Class/Name/Here.php';
new Guzzle\Http\Client(); // require('/some/root/path/Guzzle/Http/Client.php');
Thrown off lists.php.net, moved to Google Groups
Admitted a few new projects
Slept through 2010
Debated a lot in 2011
We need a dependency system!
—Jordi Boggiano
Nils Aderman (PHPBB): libzypp -> PHP
Jordi Boggiano (Monolog): Packagist, front-end for PEAR
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.
— Jordi Boggiano
September 2012
Composer from the ground up
June 2014: 33,000 packages
(Not just Symfony!)
# Quick-n-easy: $ curl -sS https://getcomposer.org/installer | php # Global $ curl -sS https://getcomposer.org/installer | php -- --install-dir=bin
Base manifest file for your project
{ "name": "crell/myapp", "description": "This app is amazing.", "require": { "guzzle/guzzle": "3.4.*" }, "autoload": { "psr-0": { "MyName\\MyPackage": "src/" } } }
Installs all dependencies for your project
$ composer.phar install Loading composer repositories with package information Installing dependencies (including require-dev) - Installing symfony/event-dispatcher (v2.3.1) Downloading: 100% - Installing guzzle/guzzle (v3.4.3) Downloading: 100% symfony/event-dispatcher suggests installing symfony/dependency-injection () symfony/event-dispatcher suggests installing symfony/http-kernel () Writing lock file Generating autoload files
use Guzzle\Http\Client; require_once __DIR__ . '/vendor/autoload.php'; // Every class is now yours to command! // Autoload on demand! Your work: zero. $client = new Client('https://api.github.com'); $request = $client->get('/user')->setAuth('user', 'pass'); $response = $request->send(); echo $response->getBody();
The organization formerly known as thePHP Standards Group and now represented bythis web site
Became useful in 2012
Renamed to PHP Framework Interoperability Group,June 2012
New (first?) actual process definition, July 2013
Standard logger interface
Inspired by Monolog ... and Drupal
namespace Psr\Log; interface LoggerInterface { public function log($level, $message, array $context = array()); public function emergency($message, array $context = array()); public function alert($message, array $context = array()); public function critical($message, array $context = array()); public function error($message, array $context = array()); public function warning($message, array $context = array()); public function notice($message, array $context = array()); public function info($message, array $context = array()); public function debug($message, array $context = array()); }
Unified caching interface
Editor: Yours Truly :-)
function get_widget_list() { $pool = get_cache_pool('widgets'); $item = $pool->getItem('widget_list'); if (!$item->isHit()) { $value = compute_expensive_widget_list(); $item->set($value); $pool->save($item); } return $item->get(); }
HTTP Messages
Editor: Michael Dowling, Guzzle
namespace Psr\Http\Message; interface MessageInterface { public function getProtocolVersion(); public function getBody(); public function setBody(StreamInterface $body = null); public function getHeaders(); public function hasHeader($header); public function getHeader($header); public function getHeaderAsArray($header); public function setHeader($header, $value); public function setHeaders(array $headers); public function addHeader($header, $value); public function addHeaders(array $headers); public function removeHeader($header); }
namespace Psr\Http\Message; interface RequestInterface extends MessageInterface { public function getMethod(); public function setMethod($method); public function getUrl(); public function setUrl($url); } interface ResponseInterface extends MessageInterface { public function getStatusCode(); public function setStatusCode($code); public function getReasonPhrase(); public function setReasonPhrase($phrase); }
The way to be more productive is to write less code
The way to be more productive is to reuse more code
The way to be more productive is to share more code
ProxyManager component shared by Zend and Symfony DependencyInjection Component
Great news for Symfony!
Given 2 ways to solve a problem,choose the approach that results in less code
in the world
We are no longer islands
Our world is changing fast.
Let's go somewhere together.
Senior Architect, Palantir.net
Making the Web a Better Place
Keep tabs on our work at @Palantir
Want to hear about what we're doing?