Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Put this in your pipe require 'sinatra' ! get '/hi' do "Hello World!" end

Slide 4

Slide 4 text

and source 'https://rubygems.org' gem 'sinatra'

Slide 5

Slide 5 text

smoke it $ bundle install $ bundle exec ruby hi.rb == Sinatra has taken the stage ... >> Listening on 0.0.0.0:4567 $ curl localhost:4567/hi Hello World!

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

get '/hello/:name' do "Hello #{params[:name]}!" end

Slide 9

Slide 9 text

get '/' do haml '%div.title Hello World' end

Slide 10

Slide 10 text

get '/' do haml :index end ! __END__ ! @@ layout %html = yield ! @@ index %div.title Hello world.

Slide 11

Slide 11 text

before do # ... end ! after do # ... end

Slide 12

Slide 12 text

Why? • How do we build large systems? • We don’t. • Micro-SOA • HTTP APIs

Slide 13

Slide 13 text

Questions? sinatrarb.com

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Chunking

Slide 16

Slide 16 text

Context more abstract more concrete

Slide 17

Slide 17 text

Frameworks Zero

Slide 18

Slide 18 text

Frameworks Zero Don’t re- invent the wheel! You’re bloated and buggy!

Slide 19

Slide 19 text

Frameworks Zero Conventions Libraries Wiring

Slide 20

Slide 20 text

Conventions Libraries Wiring Coding standard Directory layout Community

Slide 21

Slide 21 text

Conventions Libraries Wiring Routing ORM Templating etc.

Slide 22

Slide 22 text

Conventions Libraries Wiring Base config Library glue Bootstrap

Slide 23

Slide 23 text

Conventions Libraries Wiring Frameworks Zero

Slide 24

Slide 24 text

Conventions Libraries Wiring Frameworks Zero Because downloading stuff is hard!

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Conventions Libraries Wiring

Slide 27

Slide 27 text

Conventions Libraries Wiring

Slide 28

Slide 28 text

Conventions Libraries Wiring Libraries Frameworks

Slide 29

Slide 29 text

Questions? getcomposer.org packagist.org

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Add what you need

Slide 32

Slide 32 text

Minimal interface: ~5 classes

Slide 33

Slide 33 text

So… what is it?

Slide 34

Slide 34 text

Glorified Router

Slide 35

Slide 35 text

$app = new Silex\Application();
 
 $app->get('/', function () {
 return "Hello world!";
 }); ! $app->run();

Slide 36

Slide 36 text

$app->get('/blog/{id}', 'Blog::showPost'); ! $app->post('/blog/{id}', 'Blog::createPost'); ! $app->put('/blog/{id}', function ($id) {
 ...
 })
 ->assert('id', '\d+');

Slide 37

Slide 37 text

$app->before(function () {
 ...
 });
 
 $app->after(function () {
 ...
 });
 
 $app->finish(function () {
 ...
 });

Slide 38

Slide 38 text

use Symfony\Component\HttpFoundation\Response;
 
 $app->error(function (\Exception $e, $code) {
 return new Response('Whoops!', $code);
 });

Slide 39

Slide 39 text

$app->redirect('/hello'); ! $app->json($data); ! $app->sendFile($file);

Slide 40

Slide 40 text

Dependency Injection Container

Slide 41

Slide 41 text

class Application extends Pimple

Slide 42

Slide 42 text

$app['routes'] ! $app['url_matcher'] ! $app['kernel']

Slide 43

Slide 43 text

User Interface for Symfony2

Slide 44

Slide 44 text

http-kernel http-foundation event-dispatcher routing silex

Slide 45

Slide 45 text

REQ REP

Slide 46

Slide 46 text

diff -u symfony silex

Slide 47

Slide 47 text

--- symfony +++ silex @@ -1,3 +1 @@ -conventions -static compilation -lots of services +choices

Slide 48

Slide 48 text

Glorified Router ! ! ! ! !

Slide 49

Slide 49 text

Glorified Router ! Dependency Injection Container ! !

Slide 50

Slide 50 text

Glorified Router ! Dependency Injection Container ! User Interface for Symfony2

Slide 51

Slide 51 text

Grow your own Architecture ! Minimal Interface ! Public API: ~5 classes

Slide 52

Slide 52 text

Questions? #silex-php github.com/fabpot/Silex silex.sensiolabs.org

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

HttpKernel EventDispatcher ControllerResolver Listener A Listener B Request Response

Slide 55

Slide 55 text

HttpKernel Request Response request controller response

Slide 56

Slide 56 text

request controller RouterListener UrlMatcher

Slide 57

Slide 57 text

$kernel = new HttpKernel( $dispatcher, new ControllerResolver() ); use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\Controller\ControllerResolver;

Slide 58

Slide 58 text

use Symfony\Component\EventDispatcher\EventDispatcher; $dispatcher = new EventDispatcher();

Slide 59

Slide 59 text

use Symfony\Component\HttpKernel\EventListener\RouterListener; $dispatcher->addSubscriber( new RouterListener($matcher) );

Slide 60

Slide 60 text

use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\RequestContext; $matcher = new UrlMatcher( $routes, new RequestContext() );

Slide 61

Slide 61 text

use Symfony\Component\Routing\RouteCollection; $routes = new RouteCollection();

Slide 62

Slide 62 text

use Symfony\Component\Routing\Route; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $route = new Route('/foo', [ '_controller' => function (Request $request) { return new Response('Hello foo!'); }, ]); ! $routes->add('foo', $route);

Slide 63

Slide 63 text

$route = (new Route('/foo')) ->setDefault('_controller', ...) ->setRequirement('_method', 'POST');

Slide 64

Slide 64 text

use Symfony\Component\HttpFoundation\Request; $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send();

Slide 65

Slide 65 text

use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\Controller\ControllerResolver; use Symfony\Component\HttpKernel\EventListener\RouterListener; use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; ! $routes = new RouteCollection(); $routes->add('foo', new Route('/foo', [ '_controller' => function (Request $request) { return new Response('foo!'); }, ])); ! $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new RouterListener( new UrlMatcher($routes, new RequestContext()) )); ! $kernel = new HttpKernel($dispatcher, new ControllerResolver()); ! $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send();

Slide 66

Slide 66 text

• + container • + route builder • + facade

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

Questions? #YOLOPHP github.com/igorw/yolo yolophp.com twitter.com/stephcd

Slide 69

Slide 69 text

Ω