Commit 87e0a836 authored by Fabien Potencier's avatar Fabien Potencier

Merge branch '1.1'

* 1.1:
  Event helpers add listeners directly after boot
  fix docblock
  Update intro.rst - Included links to Symfony2, Pimple and Sinatra
  typo fixed in doc/providers.rst
parents 8c6f5974 c2d0d2ca
......@@ -2,7 +2,7 @@ Introduction
============
Silex is a PHP microframework for PHP 5.3. It is built on the shoulders of
Symfony2 and Pimple and also inspired by sinatra.
`Symfony2`_ and `Pimple`_ and also inspired by `Sinatra`_.
A microframework provides the guts for building simple single-file apps. Silex
aims to be:
......@@ -46,3 +46,6 @@ Installing Silex is as easy as it can get. `Download`_ the archive file,
extract it, and you're done!
.. _Download: http://silex.sensiolabs.org/download
.. _Symfony2: http://symfony.com/
.. _Pimple: http://pimple.sensiolabs.org/
.. _Sinatra: http://www.sinatrarb.com/
......@@ -271,6 +271,11 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
*/
public function on($eventName, $callback, $priority = 0)
{
if ($this->booted) {
$this['dispatcher']->addListener($eventName, $callback, $priority);
return;
}
$this['dispatcher'] = $this->share($this->extend('dispatcher', function ($dispatcher, $app) use ($callback, $priority, $eventName) {
$dispatcher->addListener($eventName, $callback, $priority);
......@@ -481,7 +486,7 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
/**
* Handles the request and delivers the response.
*
* @param Request $request Request to process
* @param Request|null $request Request to process
*/
public function run(Request $request = null)
{
......
......@@ -38,4 +38,23 @@ class LazyDispatcherTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($dispatcherCreated);
}
/** @test */
public function eventHelpersShouldDirectlyAddListenersAfterBoot()
{
$app = new Application();
$fired = false;
$app->get("/", function () use ($app, &$fired) {
$app->finish(function () use (&$fired) {
$fired = true;
});
});
$request = Request::create('/');
$response = $app->handle($request);
$app->terminate($request, $response);
$this->assertTrue($fired, 'Event was not fired');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment