Zend Expressive: A Quick Tour

Ian Littman (@iansltx)

AustinPHP October 2016

http://ian.im/zx1016

What is it?

  • Microframework-ish (includes views)
  • PSR-7 compliant (via Zend Diactoros)
  • Middlewares (via Zend Stratigility)
  • Mix and match components for...
    • Router
    • DI
    • Views
    • Error Handling
  • Installer includes the mix-and-match
  • Can use array-heavy or programmatic config

Go Ahead, Be Distracted

Routing

  • FastRoute
  • Zend Router
  • Aura.Router
  • Route params available via $request->getAttribute()

NOTE

Configuration options may very depending on library

  • :id (Zend) vs. {id} (FastRoute) for routing
  • Dependency injection setup (there's a shim for Pimple)

DI Containers

  • Zend ServiceManager
  • Aura.Di
  • Pimple (via Container Interop bridge)
  • Standard setup uses heavily array-based configuration
  • Setup happens in config/container.php

NOTE

You can use another container. The app expects something that works with Container Interop. If you supply that with the proper dependencies, you're good to go. It just won't show up in the installer.

Views

  • Plates
  • Twig
  • Zend View (requires Zend ServiceManager)
  • ...or none
  • Uses TemplateRenderInterface

NOTE

Views render templates. They don't create or munge responses, though they can return a StreamInterface (the built in ones don't).

ERror Handling

  • Whoops (dev only, optional)
  • TemplatedErrorHandler interface

Actions & Middlewares

  • Can define via...
    • Config (nested arrays)
    • Methods off of app object (similar to Slim etc.)
  • Actions are middlewares (no special signature)
  • May switch to PSR-15 syntax in the future

Demo Time!

Questions?

Zend Expressive - AustinPHP October 2016

By Ian Littman

Zend Expressive - AustinPHP October 2016

  • 700
Loading comments...

More from Ian Littman