Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Four Seasons of Silex

Igor Wiedler
November 27, 2013

Four Seasons of Silex

Igor Wiedler

November 27, 2013
Tweet

More Decks by Igor Wiedler

Other Decks in Programming

Transcript

  1. 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!
  2. get '/' do haml :index end ! __END__ ! @@

    layout %html = yield ! @@ index %div.title Hello world.
  3. Why? • How do we build large systems? • We

    don’t. • Micro-SOA • HTTP APIs
  4. --- symfony +++ silex @@ -1,3 +1 @@ -conventions -static

    compilation -lots of services +choices
  5. 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);
  6. 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();
  7. Ω