Skip to content

Commit

Permalink
Merge pull request #53 from pennyphp/feature/name-http-flow
Browse files Browse the repository at this point in the history
Fixed #52 Replace http.flow with eventManager
  • Loading branch information
Gianluca Arbezzano committed Sep 12, 2015
2 parents af96b3a + 69e9d8e commit b0b46e7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require_once "./vendor/autoload.php";

$app = new \GianArb\Penny\App();

$app->getContainer()->get("http.flow")->attach("*", function ($event) {
$app->getContainer()->get("event_manager")->attach("*", function ($event) {
$e = $event->getException();
if ($e instanceof Exception) {
throw $e;
Expand Down
8 changes: 4 additions & 4 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct($router = null, ContainerInterface $container = null
$container->set('router', $router);
}

$container->set('http.flow', DI\object('Zend\EventManager\EventManager'));
$container->set('event_manager', DI\object('Zend\EventManager\EventManager'));
$container->set('dispatcher', DI\object('GianArb\Penny\Dispatcher')
->constructor($container->get('router')));
$container->set('di', $container);
Expand Down Expand Up @@ -117,11 +117,11 @@ private function getDispatcher()
*
* @return HttpFlowEvent
*/
private function getHttpFlow()
private function getEventManager()
{
$container = $this->container;

return $container->get('http.flow');
return $container->get('event_manager');
}

/**
Expand All @@ -140,7 +140,7 @@ public function run($request = null, $response = null)

$container = $this->getContainer();
$dispatcher = $this->getDispatcher();
$httpFlow = $this->getHttpFlow();
$httpFlow = $this->getEventManager();

try {
$routerInfo = $dispatcher->dispatch($request);
Expand Down
8 changes: 4 additions & 4 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setUp()

$this->app = new App($router);

$this->app->getContainer()->get('http.flow')->attach('ERROR_DISPATCH', function ($e) {
$this->app->getContainer()->get('event_manager')->attach('ERROR_DISPATCH', function ($e) {
if ($e->getException() instanceof RouteNotFound) {
$response = $e->getResponse()->withStatus(404);
$e->setResponse($response);
Expand Down Expand Up @@ -84,7 +84,7 @@ public function testEventPostExecuted()
->withMethod('GET');
$response = new Response();

$this->app->getContainer()->get('http.flow')->attach('index.index', function ($e) {
$this->app->getContainer()->get('event_manager')->attach('index.index', function ($e) {
$response = $e->getResponse();
$response->getBody()->write("I'm very happy!");
$e->setResponse($response);
Expand All @@ -102,7 +102,7 @@ public function testEventPreExecuted()
->withMethod('GET');
$response = new Response();

$this->app->getContainer()->get('http.flow')->attach('index.index', function ($e) {
$this->app->getContainer()->get('event_manager')->attach('index.index', function ($e) {
$response = $e->getResponse();
$response->getBody()->write('This is');
$e->setResponse($response);
Expand All @@ -122,7 +122,7 @@ public function testEventPreThrowExceptionIsTrigger()
$response = new Response();
$count = 0;

$this->app->getContainer()->get('http.flow')->attach('index.dummy_error', function ($e) use (&$count) {
$this->app->getContainer()->get('event_manager')->attach('index.dummy_error', function ($e) use (&$count) {
$count = &$count + 1;
throw $e->getException();
}, 10);
Expand Down
4 changes: 2 additions & 2 deletions tests/EventFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public function testStopEventFlow() {
->withMethod('GET');
$response = new Response();

$this->app->getContainer()->get('http.flow')->attach('index.index', function ($e) {
$this->app->getContainer()->get('event_manager')->attach('index.index', function ($e) {
$response = $e->getResponse();
$response = $response->withStatus(201);
$e->setResponse($response);
}, 100);

$this->app->getContainer()->get('http.flow')->attach('index.index', function ($e) {
$this->app->getContainer()->get('event_manager')->attach('index.index', function ($e) {
$response = $e->getResponse();
$response = $response->withStatus(205);
$e->setResponse($response);
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/SymfonyKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testRunErrorReturnSameHttpObjects()
$requestTest = null;
$responseTest = null;

$this->app->getContainer()->get("http.flow")->attach("symfonykerneltest.index_error", function ($e) use (&$requestTest, &$responseTest) {
$this->app->getContainer()->get("event_manager")->attach("symfonykerneltest.index_error", function ($e) use (&$requestTest, &$responseTest) {
$requestTest = $e->getRequest();
$responseTest = $e->getResponse();
});
Expand Down

0 comments on commit b0b46e7

Please sign in to comment.