Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'feature/rename-bootstrap-events' into develop

  • Loading branch information...
commit c182b4f12cd9e5e1ffea08b2ead9286a79d97035 2 parents 23ccfe3 + 0297cda
@trq trq authored
View
18 lib/Proem/Bootstrap/Dispatch.php
@@ -56,7 +56,7 @@ public function in(AssetManagerInterface $assetManager)
// Trigger an event allowing client code to override defaults.
$assetManager->resolve('eventManager')->trigger(
- new Event('proem.in.dispatch'),
+ new Event('proem.in.setup.dispatch'),
function ($responseEvent) use ($assetManager) {
// Check for a customized Dispatch\Dispatcher.
if ($responseEvent->has('dispatcherAsset')) {
@@ -65,8 +65,20 @@ function ($responseEvent) use ($assetManager) {
}
);
- // Dispatch this request.
- $assetManager->resolve('dispatcher')->handle($assetManager->resolve('request'));
+ // Trigger an event allowing client code to override the way the dispatcher is called.
+ $assetManager->resolve('eventManager')->trigger(
+ new Event('proem.in.dispatch'),
+ function ($responseEvent) use ($assetManager) {
+ // Check for a customised dispatch handler.
+ if ($responseEvent->has('dispatchHandler') && $responseEvent->get('dispatcherHandler') instanceof \Closure) {
+ $action = $responseEvent->get('dispatcherHandler');
+ $action($assetManager->resolve('request'));
+ } else {
+ // Dispatch using the default handler.
+ $assetManager->resolve('dispatcher')->process($assetManager->resolve('request'));
+ }
+ }
+ );
}
/**
View
2  lib/Proem/Bootstrap/Request.php
@@ -58,7 +58,7 @@ public function in(AssetManagerInterface $assetManager)
// Trigger an event allowing client code to override defaults.
$assetManager->resolve('eventManager')->trigger(
- new Event('proem.in.request'),
+ new Event('proem.in.setup.request'),
function ($responseEvent) use ($assetManager) {
if ($responseEvent->has('requestAsset')) {
$assetManager->override('request', $responseEvent->get('requestAsset'));
View
2  lib/Proem/Bootstrap/Route.php
@@ -63,7 +63,7 @@ public function in(AssetManagerInterface $assetManager)
// Trigger an event allowing client code to override defaults.
$assetManager->resolve('eventManager')->trigger(
- new Event('proem.in.route'),
+ new Event('proem.in.setup.route'),
function ($responseEvent) use ($assetManager) {
if ($responseEvent->has('routeManagerAsset')) {
$assetManager->override('routeManager', $responseEvent->get('routeManagerAsset'));
View
27 lib/Proem/Bootstrap/Tests/DispatchTest.php
@@ -36,13 +36,13 @@ public function testCanInstantiate()
$this->assertInstanceOf('Proem\Bootstrap\Dispatch', new Dispatch);
}
- public function testCanTriggerEvent()
+ public function testTriggersEvents()
{
$eventManager = m::mock('Proem\Signal\EventManagerInterface');
$eventManager
->shouldReceive('trigger')
->with('Proem\Signal\EventInterface', 'closure')
- ->once();
+ ->twice();
$assetManager = m::mock('Proem\Service\AssetManagerInterface');
@@ -59,30 +59,9 @@ public function testCanTriggerEvent()
$assetManager
->shouldReceive('resolve')
->with('eventManager')
- ->once()
+ ->twice()
->andReturn($eventManager);
- $request = m::mock('Proem\Http\Request');
-
- $dispatcher = m::mock('Proem\Dispatch\Dispatcher');
- $dispatcher
- ->shouldReceive('handle')
- ->with($request)
- ->once()
- ->andReturn(true);
-
- $assetManager
- ->shouldReceive('resolve')
- ->with('dispatcher')
- ->once()
- ->andReturn($dispatcher);
-
- $assetManager
- ->shouldReceive('resolve')
- ->with('request')
- ->once()
- ->andReturn($request);
-
$dispatch = new Dispatch;
$dispatch->in($assetManager);
}
Please sign in to comment.
Something went wrong with that request. Please try again.