Permalink
Browse files

Bootstrap setup.

  • Loading branch information...
1 parent 3d49e96 commit 8de7b691e36d5213582d1de61fc2509abc64b381 @trq trq committed Jan 23, 2013
@@ -31,7 +31,6 @@
namespace Proem\Bootstrap;
use Proem\Service\AssetManagerInterface;
-use Proem\Service\AssetInterface;
use Proem\Filter\ChainEventAbstract;
use Proem\Signal\Event;
@@ -48,27 +47,33 @@ class Dispatch extends ChainEventAbstract
*/
public function in(AssetManagerInterface $assetManager)
{
- //$assetManager->alias([
- // 'Proem\Dispatch\DispatcherInterface' => 'Proem\Dispatch\Dispatcher',
- // 'dispatcher' => 'Proem\Dispatch\DispatcherInterface'
- //])->attach('dispatcher', function() { return new Dispatcher; }, true);
-
+ // Setup defaults.
+ $assetManager->alias([
+ 'Proem\Dispatch\DispatcherInterface' => 'Proem\Dispatch\Dispatcher',
+ 'dispatcher' => 'Proem\Dispatch\DispatcherInterface',
+ 'Proem\Dispatch\StageInterface' => 'Proem\Dispatch\Stage',
+ 'stage' => 'Proem\Dispatch\StageInterface'
+ ])
+ ->singleton('dispatcher')
+ ->singleton('stage');
+ // Trigger an event allowing client code to override defaults.
$assetManager->resolve('eventManager')->trigger(
new Event('proem.in.dispatch'),
function ($responseEvent) use ($assetManager) {
// Check for a customized Dispatch\Dispatcher.
if ($responseEvent->has('dispatcherAsset')) {
- $assetManager->override('dispatcher', $responseEvent->get('dispatcherAsset'));
+ $assetManager->overrideAsSingleton('dispatcher', $responseEvent->get('dispatcherAsset'));
}
// Check for a customized Dispatch\Staging
if ($responseEvent->has('stageAsset')) {
- $assetManager->override('stage', $responseEvent->get('stageAsset'));
+ $assetManager->overrideAsSingleton('stage', $responseEvent->get('stageAsset'));
}
}
);
+ // Dispatch this request.
$assetManager->resolve('stage')->process();
}
@@ -31,10 +31,8 @@
namespace Proem\Bootstrap;
use Proem\Service\AssetManagerInterface;
-use Proem\Service\AssetInterface;
use Proem\Filter\ChainEventAbstract;
use Proem\Signal\Event;
-use Proem\Service\AssetComposer;
/**
* The default "Request" filter chain event.
@@ -55,6 +53,10 @@ class Request extends ChainEventAbstract
*/
public function in(AssetManagerInterface $assetManager)
{
+ // Setup defaults.
+ $assetManager->alias(['request' => 'Proem\Http\Request'])->singleton('request');
+
+ // Trigger an event allowing client code to override defaults.
$assetManager->resolve('eventManager')->trigger(
new Event('proem.in.request'),
function ($responseEvent) use ($assetManager) {
@@ -55,6 +55,13 @@ class Route extends ChainEventAbstract
*/
public function in(AssetManagerInterface $assetManager)
{
+ // Setup defaults.
+ $assetManager->alias([
+ 'Proem\Routing\RouteManagerInterface' => 'Proem\Routing\RouteManager',
+ 'routeManager' => 'Proem\Routing\RouteManagerInterface',
+ ])->singleton('routeManager');
+
+ // Trigger an event allowing client code to override defaults.
$assetManager->resolve('eventManager')->trigger(
new Event('proem.in.route'),
function ($responseEvent) use ($assetManager) {
@@ -47,6 +47,16 @@ public function testCanTriggerEvent()
$assetManager = m::mock('Proem\Service\AssetManagerInterface');
$assetManager
+ ->shouldReceive('alias')
+ ->once()
+ ->andReturn($assetManager);
+
+ $assetManager
+ ->shouldReceive('singleton')
+ ->twice()
+ ->andReturn($assetManager);
+
+ $assetManager
->shouldReceive('resolve')
->with('eventManager')
->once()
@@ -49,6 +49,16 @@ public function testCanTriggerEvent()
$assetManager = m::mock('Proem\Service\AssetManagerInterface');
$assetManager
+ ->shouldReceive('alias')
+ ->once()
+ ->andReturn($assetManager);
+
+ $assetManager
+ ->shouldReceive('singleton')
+ ->once()
+ ->andReturn($assetManager);
+
+ $assetManager
->shouldReceive('resolve')
->with('eventManager')
->once()
@@ -47,6 +47,16 @@ public function testCanTriggerEvent()
$assetManager = m::mock('Proem\Service\AssetManagerInterface');
$assetManager
+ ->shouldReceive('alias')
+ ->once()
+ ->andReturn($assetManager);
+
+ $assetManager
+ ->shouldReceive('singleton')
+ ->once()
+ ->andReturn($assetManager);
+
+ $assetManager
->shouldReceive('resolve')
->with('eventManager')
->once()
@@ -21,6 +21,7 @@
"proem-components/service": "0.10.*@dev",
"proem-components/signal": "0.10.*@dev",
"proem-components/filter": "0.10.*@dev",
+ "proem-components/dispatch": "0.10.*@dev",
"proem-components/routing": "0.10.*@dev",
"proem-components/http": "0.10.*@dev"
},

0 comments on commit 8de7b69

Please sign in to comment.