international php2011_jordi boggiano_php reset
TRANSCRIPT
PHP Reset
Jordi Boggiano @seldaekhttp://nelm.io/
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
DisclaimerThis is not about REST
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
About MeBelgian living in ZürichWeby stuff for 10 yearshttp://seld.beSymfony2 core dev and other OSS contributionshttp://github.com/SeldaekRecently started Nelmiohttp://nelm.ioWe do Symfony2 & Frontend Performance consulting
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Planning
Small RantNew Frameworks & LibrariesGitHub Commercial BreakBest PracticesComposerWishful Thinking
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
A bit of history
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
PHP4 - 22-May-200001 class Foo_Bar_Baz02 {03 var $foo;04 05 function Foo_Bar_Baz()06 {07 }08 09 function bar()10 {11 }12 }
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
PHP5 - 13-Jul-200401 class Foo_Bar_Baz02 {03 public $foo;04 05 public function __construct()06 {07 }08 09 private function bar()10 {11 }12 }
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Could you spot the differences?
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Yet seven years later~20% of servers still run PHP4
Source: @iliaa's PHP Advent article, December 2010.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
PHP5.3 - 30-Jun-200901 namespace Foo\Bar;02 03 class Baz04 {05 public $foo;06 07 public function __construct()08 {09 }10 11 private function bar()12 {13 }14 }
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Again, not much has changed.But it changes everything.
Backslash\Means\No\Backwards\Compatibility
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
We've been sitting on our assesfor too long.
It's time for a change.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
New Frameworks
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Symfony2LithiumSilexZF2....
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
New Libraries
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
AsseticAsset management & processing
Combine & Compress JS, CSSCompile CoffeeScript, SASS, LESS, ..Re-encode imagesAll on the fly with cache or pre-processedInspired by Python's WebAssetsShipped with Symfony2
http://github.com/kriswallsmith/assetic
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Doctrine2DBAL, ORM, ODMs
Document stores (MongoDB, CouchDB,PHPCR, XML)Common interfaces allow for interop andknowledge re-usePropel2 builds on top of itShipped with Symfony2
http://github.com/doctrine
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
MonologLogging
FingersCrossedHandler for productionLog to files, FirePHP, emails, etc.Inspired by Python's LogbookShipped with Symfony2
http://github.com/Seldaek/monolog
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
TwigTemplate engine
Automatic escapingSeparation of concerns(Readability)Inspired by Python's Jinja2Shipped with Symfony2
http://github.com/fabpot/Twig
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
GaufretteFilesystem abstraction
Code once, store files anywhereS3, Memory, FTP, Rackspace, ..Transparently cache calls to slow backends
http://github.com/knplabs/Gaufrette
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
SnappyGenerates PDF/images from webpages
Uses wkhtmltopdf/wkhtmltoimageGood example of a small single-purposelibrary
http://github.com/knplabs/snappy
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
ImagineImage manipulation
API that doesn't suckSupports GD2, Imagick, GmagickEasily resize, crop, and moreInspired by Python's PIL & others
http://github.com/avalanche123/Imagine
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
BuzzHTTP requests
API that doesn't suckWraps around CURL
http://github.com/kriswallsmith/Buzz
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
GoutteWeb Crawler
Supports CSS3 selectors to extract contentEasily follow links, submit forms, etc.Good example of code re-use (Sf2/ZF2components)
http://github.com/fabpot/Goutte
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
I can't list them all.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
GitHub
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Git will hurt youRead http://progit.org - it's free.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
GitHub is your friend
No need to track down a developer'semail. Hit fork, create a branch, then senda pull requestPush code, get immediate attention andcontributorsREADME.mdown in every repository200 Symfony2 contributors, still in beta!
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Best Practices
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
MIT LicenseFree as in free.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Autoload with PSR-0
http://tinyurl.com/psr0-standard
01 // One class per file02 // First bit should be a vendor name (your project, company, ..)03 // This should sit in <project>/Nelmio/Bar/Baz.php04 // WATCH THE CASE!05 06 namespace Nelmio\Bar;07 08 class Baz09 {10 }
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
PEAR-style Coding Standards
http://pear.php.net/manual/en/standards.php
01 namespace Foo\Bar;02 03 class Baz04 {05 public $foo;06 07 public function __construct()08 {09 $stuff = array('Coding Style');10 if (true) {11 foreach ($stuff as $blob) {12 echo "happy $blob!";13 }14 } else {15 echo "dead kittens";16 }17 }18 }
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Remember, kids, standardsare NOT about taste
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Testing
Tests are always good, but for librariesthey're a must.Typing phpunit in <project>/ is all I wantto know.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Composer
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Package Management for PHP
Mostly inspired by npm and bundlerAdvanced dependency resolvingInstall project dependencies locally
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Compose great things with small libraries
Rely on proven code to do common tasksSimplify old APIs (e.g. Imagine, Buzz)
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
composer.json (lib)01 {02 "name": "Monolog",03 "description": "Logging for PHP 5.3",04 "keywords": ["log","logging"],05 "homepage": "http://github.com/Seldaek/monolog",06 "version": "1.0.0",07 "license": "MIT",08 "authors": [09 {10 "name": "Jordi Boggiano",11 "email": "[email protected]",12 "homepage": "http://seld.be"13 }14 ],15 "require": {16 "php": ">=5.3.0"17 }18 }
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
composer.json (project)01 {02 "repositories": {03 "AwesomeLib": {04 "git": "git://github.com/Jim/AwesomeLib.git"05 },06 "GreatLib": {07 "git-bare": {08 "url": "git://github.com/Bob/GreatLib.git",09 "version": "1.0.0"10 }11 }12 },13 "require": {14 "Twig": ">=1.0.0",15 "AwesomeLib": "latest",16 "GreatLib": "1.0.0",17 "Monolog": "latest"18 }19 }
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Demo, kind of.(blame @naderman :)
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Fear code re-use no more.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Last words
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Namespace adoption, in effect,opens up a world of
possibilities.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Open up your mind, we're not alone.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Share your codeand collaborate.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Thank you.
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be
Feedback please on:http://joind.in/3489
Slides:http://slides.seld.be
Contact me:@seldaek || [email protected]
Jordi Boggiano Company http://nelm.iohttp://twitter.com/seldaek Blog http://seld.be