Skip to content

Commit

Permalink
Initial work renaming bootstrap events and adding a new *disaptch*
Browse files Browse the repository at this point in the history
event.
  • Loading branch information
trq committed Jan 28, 2013
1 parent 23ccfe3 commit 0297cda
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
18 changes: 15 additions & 3 deletions lib/Proem/Bootstrap/Dispatch.php
Expand Up @@ -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')) {
Expand All @@ -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'));
}
}
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Proem/Bootstrap/Request.php
Expand Up @@ -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'));
Expand Down
2 changes: 1 addition & 1 deletion lib/Proem/Bootstrap/Route.php
Expand Up @@ -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'));
Expand Down
27 changes: 3 additions & 24 deletions lib/Proem/Bootstrap/Tests/DispatchTest.php
Expand Up @@ -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');

Expand All @@ -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);
}
Expand Down

0 comments on commit 0297cda

Please sign in to comment.