Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'feature/bootstrap-setup' into develop

  • Loading branch information...
commit 0e970c383b3004211c3fbc94755b2fb6d6fb74dd 2 parents 856b854 + 8de7b69
@trq trq authored
View
21 lib/Proem/Bootstrap/Dispatch.php
@@ -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();
}
View
6 lib/Proem/Bootstrap/Request.php
@@ -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) {
View
7 lib/Proem/Bootstrap/Route.php
@@ -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) {
View
10 lib/Proem/Bootstrap/Tests/DispatchTest.php
@@ -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()
View
10 lib/Proem/Bootstrap/Tests/RequestTest.php
@@ -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()
View
10 lib/Proem/Bootstrap/Tests/RouteTest.php
@@ -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()
View
1  lib/Proem/Bootstrap/composer.json
@@ -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"
},
View
22 lib/Proem/Service/AssetManager.php
@@ -136,10 +136,14 @@ public function attach($name, $resolver = null, $single = false, $override = fal
/**
* A convenience method for adding a singleton.
+ *
+ * @param string name
+ * @param Proem\Service\Asset|closure|object $resolver Some means of resolving this asset.
+ * @param bool
*/
public function singleton($name, $resolver = null, $override = false)
{
- $this->attach($name, $resolver, true, $override);
+ return $this->attach($name, $resolver, true, $override);
}
/**
@@ -150,9 +154,19 @@ public function singleton($name, $resolver = null, $override = false)
* @param bool $single
*/
public function override($name, $resolver = null, $single = false) {
- $this->attach($name, $resolver, $single, true);
+ return $this->attach($name, $resolver, $single, true);
+ }
- return $this;
+ /**
+ * A convenience method for overriding an existing singleton.
+ *
+ * @param string name
+ * @param Proem\Service\Asset|closure|object $resolver Some means of resolving this asset.
+ * @param bool
+ */
+ public function overrideAsSingleton($name, $resolver = null)
+ {
+ return $this->singleton($name, $resolver, true, true);
}
/**
@@ -246,6 +260,8 @@ protected function setParam($type, $index, $value, $override = false) {
} else if (!isset($this->{$type}[$index])) {
$this->{$type}[$index] = $value;
}
+
+ return $this;
}
/**
View
18 lib/Proem/Service/Tests/AssetManagerFixtures/DepsOnAssetManager.php
@@ -0,0 +1,18 @@
+<?php
+
+use \Proem\Service\AssetManager;
+
+class DepsOnAssetManager
+{
+ protected $am;
+
+ public function __construct(AssetManager $am)
+ {
+ $this-> am = $am;
+ }
+
+ public function getAssetManager()
+ {
+ return $this->am;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.