laravel and composer

66
Compose all the things @philsturgeon Tuesday, 26 February 13

Upload: phil-sturgeon

Post on 06-May-2015

7.070 views

Category:

Documents


7 download

DESCRIPTION

Composer is moving over to use Laravel, which requires command line stuff and a bunch of new thinking as to how code is managed. Also, my bundles have vanished, and now we're using camelCase instead of snake_case? Sit down for a history lesson about why packages have always been a mess, why frameworks have been the way they were and why they're changing in this "PHP Renaissance" to use awesome new tools like Composer.

TRANSCRIPT

Page 1: Laravel and Composer

Compose all the things@philsturgeon

Tuesday, 26 February 13

Page 2: Laravel and Composer

Derp derpy derp!

Kapture

PyroCMS

CodeIgniter

FuelPHP

PancakeApp

PHP The Right Way

PHP Town Hall

PHP-FIG

I have a weird accent

@philsturgeon

Tuesday, 26 February 13

Page 3: Laravel and Composer

“I could spend 10 minutes writing some code, but [stuff] that, I can just install a Gem.”

-- Elliott Kember, RiotHQ

Tuesday, 26 February 13

Page 4: Laravel and Composer

Ruby Gems

Warden - Simple generic authentication

OmniAuth - Integrate Facebook, Twitter, etc

OAuth / OAuth 2 - Go-to gems for oauth

Thor or Clam - Command line frameworks

ActiveRecord - THE ORM for Ruby

Tuesday, 26 February 13

Page 5: Laravel and Composer

Python (PIP)

Requests - THE HTTP class

PIL - Image Manipulation (but doesnt suck)

UJSON - UTF-8 support + way faster

Flask - RESTful micro-framework

PyYAML - Quick YAML parser

Tuesday, 26 February 13

Page 6: Laravel and Composer

Tuesday, 26 February 13

Page 7: Laravel and Composer

Tuesday, 26 February 13

Page 8: Laravel and Composer

What about PHP?

Tuesday, 26 February 13

Page 9: Laravel and Composer

Tuesday, 26 February 13

Page 10: Laravel and Composer

Tuesday, 26 February 13

Page 11: Laravel and Composer

Tuesday, 26 February 13

Page 12: Laravel and Composer

sudo apt-get install php-pear php5-dev

sudo pear channel-discover pear.phpunit.de

sudo pear install phpunit/PHPUnit

Installing stuff with PEAR

Tuesday, 26 February 13

Page 13: Laravel and Composer

Cool story bro

Tuesday, 26 February 13

Page 14: Laravel and Composer

“Active Package”

Tuesday, 26 February 13

Page 15: Laravel and Composer

“Modern Package”

Tuesday, 26 February 13

Page 16: Laravel and Composer

Tuesday, 26 February 13

Page 17: Laravel and Composer

Tuesday, 26 February 13

Page 18: Laravel and Composer

Tuesday, 26 February 13

Page 19: Laravel and Composer

Tuesday, 26 February 13

Page 20: Laravel and Composer

The Dawn of Frameworks!

Tuesday, 26 February 13

Page 21: Laravel and Composer

Tuesday, 26 February 13

Page 22: Laravel and Composer

Tuesday, 26 February 13

Page 23: Laravel and Composer

Tuesday, 26 February 13

Page 24: Laravel and Composer

Write ALL THE CODE

DATABAZE!!

Benchmarking

Cache

Calender

Email

Shopping Cart?

Encryption

Uploads

Image Manipulation

Language

Pagination

Security

CodeIgniter

Tuesday, 26 February 13

Page 25: Laravel and Composer

Tuesday, 26 February 13

Page 26: Laravel and Composer

Tuesday, 26 February 13

Page 27: Laravel and Composer

Write ALL THE CODE

Benchmarking

Cache

Calender

Cart

Driver

Email

Encryption

Uploads

Image Manipulation

Language

Pagination

Security

CodeIgniterKohanaORMHTTPUTF-8

TemplatesHMVC

Tuesday, 26 February 13

Page 28: Laravel and Composer

Write ALL THE CODE

Benchmarking

Cache

Calender

Cart

Driver

Email

Encryption

Uploads

Image Manipulation

Language

Pagination

Security

CodeIgniter

FuelPHPREST

ScaffoldingMigrations

AuthMore Mongo

KohanaORMHTTPUTF-8

TemplatesHMVC

Tuesday, 26 February 13

Page 29: Laravel and Composer

Write ALL THE CODE

Benchmarking

Cache

Calender

Cart

Driver

Email

Encryption

Uploads

Image Manipulation

Language

Pagination

Security

CodeIgniter

FuelPHPREST

ScaffoldingMigrations

AuthMore Mongo

Laravel 3Epic RoutesCALLBACKS

IoCBundles

KohanaORMHTTPUTF-8

TemplatesHMVC

Tuesday, 26 February 13

Page 30: Laravel and Composer

FW Packages = Solution?

CodeIgniter: Sparks

FuelPHP: Cells

Laravel 3: Bundles

Tuesday, 26 February 13

Page 31: Laravel and Composer

codeigniter-oauth2

fuel-oauth2

laravel-oauth2

Tuesday, 26 February 13

Page 32: Laravel and Composer

Tuesday, 26 February 13

Page 33: Laravel and Composer

Tuesday, 26 February 13

Page 34: Laravel and Composer

Composer Setup

$ mkdir playground

$ cd playground

$ curl -s https://getcomposer.org/installer | php

$ ls

composer.phar

$ vim composer.json

Tuesday, 26 February 13

Page 35: Laravel and Composer

Require Packages

{

"minimum-stability": "beta",

"require": {

"dflydev/markdown": "1.0.*",

"illuminate/database": "*"

}

}

Tuesday, 26 February 13

Page 36: Laravel and Composer

Install those Packages

$ ./composer.phar install

Loading composer repositories with package information

Installing dependencies

- Installing dflydev/markdown (v1.0.2)

Downloading: 100%

....... and so on

Tuesday, 26 February 13

Page 37: Laravel and Composer

Other Repos

{ "repositories": [ { "type": "vcs", "url": "http://github.com/mycompany/privaterepo" }, { "type": "vcs", "url": "http://svn.example.org/private/repo" }, { "type": "vcs", "url": "http://github.com/mycompany/privaterepo2" } ], "require": { "company/package": "*", "company/package2": "*", "company/package3": "2.0.0" }}

Tuesday, 26 February 13

Page 38: Laravel and Composer

Tuesday, 26 February 13

Page 39: Laravel and Composer

Why not just use them?

Boilerplate makes kittens cry

Service Providers + Facade avoid boilerplate

IoC is SIMPLE + Controller integration

Lowest barrier to entry

Tuesday, 26 February 13

Page 40: Laravel and Composer

Tuesday, 26 February 13

Page 41: Laravel and Composer

Tuesday, 26 February 13

Page 43: Laravel and Composer

Cloning Laravel 4

$ git clone git://github.com/laravel/laravel.git

-o laravel -b develop playground

Tuesday, 26 February 13

Page 44: Laravel and Composer

Install Dependencies

$ cd playground

$ curl -s https://getcomposer.org/installer | php

$ ./composer.phar install

Tuesday, 26 February 13

Page 45: Laravel and Composer

Building a Package

$ php artisan workbench

What is vendor name of the package?Epic

What is the package name?Unicorn

What is your name?Phil Sturgeon

What is your e-mail [email protected]

Tuesday, 26 February 13

Page 46: Laravel and Composer

Understanding Structure

Tuesday, 26 February 13

Page 47: Laravel and Composer

Workbench Structure

workbench epic unicorn .travis.yml composer.json phpunit.xml public src Epic Unicorn UnicornServiceProvider.php config lang migrations views tests

Tuesday, 26 February 13

Page 48: Laravel and Composer

Metadata{

"name": "epic/unicorn", "authors": [ { "name": "Phil Sturgeon", "email": "[email protected]" } ], "require": { "php": ">=5.3.0", "illuminate/support": "4.0.x" }, "autoload": { "classmap": [ "src/migrations" ], "psr-0": { "Epic\\Unicorn": "src/" } }, "minimum-stability": "dev"}

Tuesday, 26 February 13

Page 49: Laravel and Composer

Unit-tests

phpunit.de

travis-ci.org

Tuesday, 26 February 13

Page 50: Laravel and Composer

.travis.yml

language: php

php: - 5.3 - 5.4

before_script: - curl -s http://getcomposer.org/installer | php - php composer.phar install --dev

script: phpunit

Tuesday, 26 February 13

Page 51: Laravel and Composer

PSR-WAT?PHP Standard Recommendation

PHP-FIG: Framework Interoperability Group

Website: php-fig.org

Drupal, Joomla, phpBB, Symfony2, PyroCMS, FLOW, Lithium, Zend Framework, AWS SDK, CakePHP, Doctrine, PEAR, Propel, Zikula, others...

Hopefully Laravel soon.

Tuesday, 26 February 13

Page 52: Laravel and Composer

PSR-0Autoloading Standard

\<Vendor Name>\(<Namespace>\)*<Class Name>

Classes Session_Cache is Session/Cache.php

Must have a top-level namespace

http://bit.ly/PSR-0

Tuesday, 26 February 13

Page 53: Laravel and Composer

PSR-1Basic Coding Standard

Files are UTF-8

Definition OR side-effect

Constants are upper-case

Class names are StudlyCaps

Method names camelCase()

http://bit.ly/PSR-one

Tuesday, 26 February 13

Page 54: Laravel and Composer

PSR-2Coding Style Guide

SHOULD limit to 80 or 120 characters per line

All PHP files MUST use the Unix LF (linefeed) line ending.

The closing ?> tag MUST be omitted from files containing only PHP.

MUST use 4 spaces for indentation, not tabs

http://bit.ly/PSR-2

Tuesday, 26 February 13

Page 55: Laravel and Composer

Should you PSR-2?

PSR-0 and PSR-1 are no brainers

PSR-2 was split from PSR-1 as its controversial

Tabs v Spaces? I don’t care.

Laravel is PSR-2ish

Tuesday, 26 February 13

Page 56: Laravel and Composer

codeigniter-oauth2

fuel-oauth2

laravel-oauth2

Tuesday, 26 February 13

Page 57: Laravel and Composer

Interfaces for the Win

Tuesday, 26 February 13

Page 58: Laravel and Composer

Framework Driver Basics

interface SessionInterface { public function getKey(); public function put($value); public function get(); public function forget();}

Tuesday, 26 February 13

Page 59: Laravel and Composer

Framework Driver Basics

use Fuel\Core\Session_Driver as Session;

class FuelPHPSession implements SessionInterface

class NativeSession implements SessionInterface

use CI_Session as Session;

class CISession implements SessionInterface

use Illuminate\Session\Store as SessionStore;

class IlluminateSession implements SessionInterface

Tuesday, 26 February 13

Page 60: Laravel and Composer

Framework Driver Basics

use CI_Session as Session;

class CISession implements SessionInterface{ public function __construct(Session $store) { $this->store = $store; } }

Tuesday, 26 February 13

Page 61: Laravel and Composer

Framework Driver Basics public function put($value) { $this->store->set_userdata(

$this->getkey(),serialize($value));

}

public function forget() { $this->store->unset_userdata(

$this->getKey());

}

Tuesday, 26 February 13

Page 62: Laravel and Composer

Tuesday, 26 February 13

Page 63: Laravel and Composer

PyroCMS

PyroCMS 2.2 = PHP 5.2 + CodeIgniter

PyroCMS 2.3 = PHP 5.3 + Composer + CodeIgniter

PyroCMS 3.0 = PHP 5.3 + Composer + Laravel

Tuesday, 26 February 13

Page 64: Laravel and Composer

PyroCMS Depenencies dflydev/markdowndhorrigan/capsuleircmaxell/password-compatilluminate/databasenesbot/Carbonquick/cachesimplepie/simplepietijsverkoyen/akismet

Tuesday, 26 February 13

Page 65: Laravel and Composer

Any Questions?

What was that thing you said about PSR?

Are you Australian?

Is camelCase web-scale?

Do you prefer Tabs or Spaces?

Why doesn’t PyroCMS support MongoDB?

Tuesday, 26 February 13

Page 66: Laravel and Composer

Thank You

philsturgeon.co.uk

github.com/philsturgeon

@philsturgeon

Tuesday, 26 February 13