Created
January 22, 2012 10:22
-
-
Save trq/1656493 to your computer and use it in GitHub Desktop.
Filter Chain Event as Service Asset.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Proem/Api/Bootstrap/Service/Asset/Dispatch.php b/lib/Proem/Api/Bootstrap/Service/Asset/Dispatch.php | |
new file mode 100644 | |
index 0000000..5b1c194 | |
--- /dev/null | |
+++ b/lib/Proem/Api/Bootstrap/Service/Asset/Dispatch.php | |
@@ -0,0 +1,49 @@ | |
+<?php | |
+ | |
+/** | |
+ * The MIT License | |
+ * | |
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | |
+ * | |
+ * Permission is hereby granted, free of charge, to any person obtaining a copy | |
+ * of this software and associated documentation files (the "Software"), to deal | |
+ * in the Software without restriction, including without limitation the rights | |
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
+ * copies of the Software, and to permit persons to whom the Software is | |
+ * furnished to do so, subject to the following conditions: | |
+ * | |
+ * The above copyright notice and this permission notice shall be included in | |
+ * all copies or substantial portions of the Software. | |
+ * | |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
+ * THE SOFTWARE. | |
+ */ | |
+ | |
+ | |
+/** | |
+ * @namespace Proem\Api\Bootstrap\Service\Asset | |
+ */ | |
+namespace Proem\Api\Bootstrap\Service\Asset; | |
+ | |
+use Proem\Bootstrap\Filter\Event\Dispatch as DispatchEvent; | |
+ | |
+/** | |
+ * Proem\Api\Bootstrap\Service\Asset\Dispatch | |
+ * | |
+ * The default "Dispatch" asset capable of creating a Dispatch Filter Event. | |
+ */ | |
+class Dispatch extends \Proem\Service\Asset\Generic | |
+{ | |
+ public function __construct() | |
+ { | |
+ $this->provides('Proem\Api\Bootstrap\Filter\Event\Dispatch') | |
+ ->set($this->single(function() { | |
+ return new DispatchEvent; | |
+ })); | |
+ } | |
+} | |
diff --git a/lib/Proem/Api/Bootstrap/Service/Asset/Request.php b/lib/Proem/Api/Bootstrap/Service/Asset/Request.php | |
new file mode 100644 | |
index 0000000..f1f5644 | |
--- /dev/null | |
+++ b/lib/Proem/Api/Bootstrap/Service/Asset/Request.php | |
@@ -0,0 +1,49 @@ | |
+<?php | |
+ | |
+/** | |
+ * The MIT License | |
+ * | |
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | |
+ * | |
+ * Permission is hereby granted, free of charge, to any person obtaining a copy | |
+ * of this software and associated documentation files (the "Software"), to deal | |
+ * in the Software without restriction, including without limitation the rights | |
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
+ * copies of the Software, and to permit persons to whom the Software is | |
+ * furnished to do so, subject to the following conditions: | |
+ * | |
+ * The above copyright notice and this permission notice shall be included in | |
+ * all copies or substantial portions of the Software. | |
+ * | |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
+ * THE SOFTWARE. | |
+ */ | |
+ | |
+ | |
+/** | |
+ * @namespace Proem\Api\Bootstrap\Service\Asset | |
+ */ | |
+namespace Proem\Api\Bootstrap\Service\Asset; | |
+ | |
+use Proem\Bootstrap\Filter\Event\Request as RequestEvent; | |
+ | |
+/** | |
+ * Proem\Api\Bootstrap\Service\Asset\Request | |
+ * | |
+ * The default "Request" asset capable of creating a Request Filter Event. | |
+ */ | |
+class Request extends \Proem\Service\Asset\Generic | |
+{ | |
+ public function __construct() | |
+ { | |
+ $this->provides('Proem\Api\Bootstrap\Filter\Event\Request') | |
+ ->set($this->single(function() { | |
+ return new RequestEvent; | |
+ })); | |
+ } | |
+} | |
diff --git a/lib/Proem/Api/Bootstrap/Service/Asset/Response.php b/lib/Proem/Api/Bootstrap/Service/Asset/Response.php | |
new file mode 100644 | |
index 0000000..336d7a2 | |
--- /dev/null | |
+++ b/lib/Proem/Api/Bootstrap/Service/Asset/Response.php | |
@@ -0,0 +1,49 @@ | |
+<?php | |
+ | |
+/** | |
+ * The MIT License | |
+ * | |
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | |
+ * | |
+ * Permission is hereby granted, free of charge, to any person obtaining a copy | |
+ * of this software and associated documentation files (the "Software"), to deal | |
+ * in the Software without restriction, including without limitation the rights | |
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
+ * copies of the Software, and to permit persons to whom the Software is | |
+ * furnished to do so, subject to the following conditions: | |
+ * | |
+ * The above copyright notice and this permission notice shall be included in | |
+ * all copies or substantial portions of the Software. | |
+ * | |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
+ * THE SOFTWARE. | |
+ */ | |
+ | |
+ | |
+/** | |
+ * @namespace Proem\Api\Bootstrap\Service\Asset | |
+ */ | |
+namespace Proem\Api\Bootstrap\Service\Asset; | |
+ | |
+use Proem\Bootstrap\Filter\Event\Response as ResponseEvent; | |
+ | |
+/** | |
+ * Proem\Api\Bootstrap\Service\Asset\Response | |
+ * | |
+ * The default "Response" asset capable of creating a Response Filter Event. | |
+ */ | |
+class Response extends \Proem\Service\Asset\Generic | |
+{ | |
+ public function __construct() | |
+ { | |
+ $this->provides('Proem\Api\Bootstrap\Filter\Event\Response') | |
+ ->set($this->single(function() { | |
+ return new ResponseEvent; | |
+ })); | |
+ } | |
+} | |
diff --git a/lib/Proem/Api/Bootstrap/Service/Asset/Route.php b/lib/Proem/Api/Bootstrap/Service/Asset/Route.php | |
new file mode 100644 | |
index 0000000..8b0adbd | |
--- /dev/null | |
+++ b/lib/Proem/Api/Bootstrap/Service/Asset/Route.php | |
@@ -0,0 +1,49 @@ | |
+<?php | |
+ | |
+/** | |
+ * The MIT License | |
+ * | |
+ * Copyright (c) 2010 - 2012 Tony R Quilkey <trq@proemframework.org> | |
+ * | |
+ * Permission is hereby granted, free of charge, to any person obtaining a copy | |
+ * of this software and associated documentation files (the "Software"), to deal | |
+ * in the Software without restriction, including without limitation the rights | |
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
+ * copies of the Software, and to permit persons to whom the Software is | |
+ * furnished to do so, subject to the following conditions: | |
+ * | |
+ * The above copyright notice and this permission notice shall be included in | |
+ * all copies or substantial portions of the Software. | |
+ * | |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
+ * THE SOFTWARE. | |
+ */ | |
+ | |
+ | |
+/** | |
+ * @namespace Proem\Api\Bootstrap\Service\Asset | |
+ */ | |
+namespace Proem\Api\Bootstrap\Service\Asset; | |
+ | |
+use Proem\Bootstrap\Filter\Event\Route as RouteEvent; | |
+ | |
+/** | |
+ * Proem\Api\Bootstrap\Service\Asset\Route | |
+ * | |
+ * The default "Route" asset capable of creating a Route Filter Event. | |
+ */ | |
+class Route extends \Proem\Service\Asset\Generic | |
+{ | |
+ public function __construct() | |
+ { | |
+ $this->provides('Proem\Api\Bootstrap\Filter\Event\Dispatch') | |
+ ->set($this->single(function() { | |
+ return new RouteEvent; | |
+ })); | |
+ } | |
+} | |
diff --git a/lib/Proem/Api/Filter/Chain.php b/lib/Proem/Api/Filter/Chain.php | |
index 145d910..4910c99 100644 | |
--- a/lib/Proem/Api/Filter/Chain.php | |
+++ b/lib/Proem/Api/Filter/Chain.php | |
@@ -30,7 +30,7 @@ | |
*/ | |
namespace Proem\Api\Filter; | |
-use Proem\Filter\Event\Generic as Event, | |
+use Proem\Service\Asset\Generic as Asset, | |
Proem\Util\Storage\Queue, | |
Proem\Service\Manager; | |
@@ -73,11 +73,11 @@ class Chain | |
} | |
/** | |
- * Insert an event into the queue | |
+ * Insert an Event Asset into the queue | |
* | |
* @return Proem\Api\Filter\Chain | |
*/ | |
- public function insertEvent(Event $event, $priority = self::RESPONSE_EVENT_PRIORITY) | |
+ public function insertEvent(Asset $event, $priority = self::RESPONSE_EVENT_PRIORITY) | |
{ | |
$this->queue->insert($event, $priority); | |
return $this; | |
@@ -129,7 +129,7 @@ class Chain | |
*/ | |
public function init() | |
{ | |
- return $this->getInitialEvent()->init($this); | |
+ return $this->getInitialEvent()->get()->init($this); | |
} | |
} | |
diff --git a/lib/Proem/Api/Filter/Event/Generic.php b/lib/Proem/Api/Filter/Event/Generic.php | |
index ed225ab..b22be4b 100644 | |
--- a/lib/Proem/Api/Filter/Event/Generic.php | |
+++ b/lib/Proem/Api/Filter/Event/Generic.php | |
@@ -97,7 +97,7 @@ abstract class Generic | |
if ($chain->hasEvents()) { | |
$event = $chain->getNextEvent(); | |
if (is_object($event)) { | |
- $event->init($chain); | |
+ $event->get()->init($chain); | |
} | |
} | |
diff --git a/lib/Proem/Api/Proem.php b/lib/Proem/Api/Proem.php | |
index 8388c94..6e0e7ad 100644 | |
--- a/lib/Proem/Api/Proem.php | |
+++ b/lib/Proem/Api/Proem.php | |
@@ -32,10 +32,10 @@ namespace Proem\Api; | |
use Proem\Service\Manager as ServiceManager, | |
Proem\Signal\Manager as SignalManager, | |
Proem\Service\Asset\Generic as GenericAsset, | |
- Proem\Bootstrap\Filter\Event\Response, | |
- Proem\Bootstrap\Filter\Event\Request, | |
- Proem\Bootstrap\Filter\Event\Route, | |
- Proem\Bootstrap\Filter\Event\Dispatch, | |
+ Proem\Bootstrap\Service\Asset\Response, | |
+ Proem\Bootstrap\Service\Asset\Request, | |
+ Proem\Bootstrap\Service\Asset\Route, | |
+ Proem\Bootstrap\Service\Asset\Dispatch, | |
Proem\Bootstrap\Signal\Event\Bootstrap, | |
Proem\Filter\Chain; | |
diff --git a/tests/lib/Proem/Tests/FilterTest.php b/tests/lib/Proem/Tests/FilterTest.php | |
index 58047b5..27688de 100644 | |
--- a/tests/lib/Proem/Tests/FilterTest.php | |
+++ b/tests/lib/Proem/Tests/FilterTest.php | |
@@ -27,7 +27,8 @@ | |
namespace Proem\Tests; | |
use Proem\Filter\Chain, | |
- Proem\Service\Manager; | |
+ Proem\Service\Manager, | |
+ Proem\Service\Asset\Generic as Asset; | |
class FilterTest extends \PHPUnit_Framework_TestCase | |
{ | |
@@ -63,10 +64,10 @@ class FilterTest extends \PHPUnit_Framework_TestCase | |
$this->dispatch->expects($this->once())->method('outBound')->will($this->returnCallback(function() use ($r) {$r->out .= "dispatch out, ";})); | |
(new Chain(new Manager)) | |
- ->insertEvent($this->response, Chain::RESPONSE_EVENT_PRIORITY) | |
- ->insertEvent($this->request, Chain::REQUEST_EVENT_PRIORITY) | |
- ->insertEvent($this->route, Chain::ROUTE_EVENT_PRIORITY) | |
- ->insertEvent($this->dispatch, Chain::DISPATCH_EVENT_PRIORITY) | |
+ ->insertEvent((new Asset)->set(function () { return $this->response; }), Chain::RESPONSE_EVENT_PRIORITY) | |
+ ->insertEvent((new Asset)->set(function() { return $this->request; }), Chain::REQUEST_EVENT_PRIORITY) | |
+ ->insertEvent((new Asset)->set(function() { return $this->route; }), Chain::ROUTE_EVENT_PRIORITY) | |
+ ->insertEvent((new Asset)->set(function() { return $this->dispatch; }), Chain::DISPATCH_EVENT_PRIORITY) | |
->init(); | |
$this->assertEquals('response in, request in, route in, dispatch in, dispatch out, route out, request out, response out', $r->out); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment