Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Created August 9, 2014 08:53
Show Gist options
  • Select an option

  • Save franz-josef-kaiser/2a2f085d75fed8cb73ed to your computer and use it in GitHub Desktop.

Select an option

Save franz-josef-kaiser/2a2f085d75fed8cb73ed to your computer and use it in GitHub Desktop.
Silex Middlewares - a PHP only (non YAML, non annotated) implementation of Symfony KernelEvents and even dispatching
  1. The Silex\Application loads the 'route_factory', which returns an instance of a Silex\Route.
  2. When mounted in a Silex\ControllerCollection, it accepts Middlewares attached to before() or after() methods. Those are actually Options for the Symfony\..\Route Component.
  3. Attached are MiddlewareListeners

So in Silex, this:

// ex. #1
$app['controllers']->before( 'callback', APPLICATION::EARLY_EVENT );

// ex. #2
$app['controllers']->after( 'callback', Application::LATE_EVENT );

is equal to

// use Symfony\Component\HttpKernel\KernelEvents;

// #1
$app->on( KernelEvents::REQUEST, 'callback' );

// #2
$app->on( KernelEvents::TERMINATE, 'callback' );

and works without annotations or YAML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment