Skip to content

Commit

Permalink
Merge pull request #142 from pennyphp/fix-139
Browse files Browse the repository at this point in the history
Fix 139
  • Loading branch information
Gianluca Arbezzano committed Nov 28, 2015
2 parents a9f0935 + 397067f commit 25ac241
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 37 deletions.
6 changes: 3 additions & 3 deletions docs/event-manager-intro.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Event Manager Introduction

Penny provides an [`PennyEvmInterface`](https://github.com/pennyphp/penny/blob/master/src/Event/PennyEvmInterface.php) that has 2 methods :
Penny provides an [`EventManagerInterface`](https://github.com/pennyphp/penny/blob/master/src/Event/EventManagerInterface.php) that has 2 methods :

```php
public function trigger(PennyEventInterface $event);
public function trigger(EventInterface $event);
public function attach($eventName, callable $listener);
```

The trigger will execute an event based on registered listeners in our Event Manager, Our Event must implement [`PennyEventInterface`](https://github.com/pennyphp/penny/blob/master/src/Event/PennyEventInterface.php) that has following methods:
The trigger will execute an event based on registered listeners in our Event Manager, Our Event must implement [`EventInterface`](https://github.com/pennyphp/penny/blob/master/src/Event/EventInterface.php) that has following methods:

```php
public function getName();
Expand Down
6 changes: 4 additions & 2 deletions docs/write-our-event-manager-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ We can write our event manager proxy with the following signature:
```php
namespace App\EventManager\Event;

use Penny\Event\EventInterface;
use Penny\Event\EventManagerInterface;
use Our\Awesome\EventManager;

class OurAwesomeEventManagerProxy implements PennyEvmInterface
class OurAwesomeEventManagerProxy implements EventManagerInterface
{
/**
* @var EventManager
Expand All @@ -25,7 +27,7 @@ class OurAwesomeEventManagerProxy implements PennyEvmInterface
/**
* {@inheritDoc}
*/
public function trigger(PennyEventInterface $event)
public function trigger(EventInterface $event)
{
$this->eventManager->trigger($event);
return $this;
Expand Down
36 changes: 19 additions & 17 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Exception;
use RuntimeException;
use Penny\Config\Loader;
use Penny\Event\PennyEvmInterface;
use Penny\Event\PennyEventInterface;
use Penny\Event\EventManagerInterface;
use Penny\Event\EventInterface;
use Penny\Route\RouteInfoInterface;
use Interop\Container\ContainerInterface;

Expand Down Expand Up @@ -67,7 +67,7 @@ private function getDispatcher()
/**
* Penny HTTP flow event getter.
*
* @return PennyEvmInterface
* @return EventManagerInterface
*/
private function getEventManager()
{
Expand All @@ -87,7 +87,7 @@ private function getEventManager()
private function setUpEventWithRequestResponse($request, $response)
{
$event = $this->getContainer()->get('http_flow_event');
if (!$event instanceof PennyEventInterface) {
if (!$event instanceof EventInterface) {
throw new RuntimeException('This event did not supported');
}

Expand Down Expand Up @@ -133,13 +133,15 @@ public function run($request = null, $response = null)
/**
* Handle Route.
*
* @param mixed $routeInfo
* @param PennyEventInterface $event
* @param RouteInfoInterface $routeInfo
* @param EventInterface $event
*
* @throws RuntimeException if dispatch does not return RouteInfo object.
*/
private function handleRoute($routeInfo, PennyEventInterface $event)
{
private function handleRoute(
RouteInfoInterface $routeInfo,
EventInterface $event
) {
if (!$routeInfo instanceof RouteInfoInterface) {
throw new RuntimeException('Dispatch does not return RouteInfo object');
}
Expand All @@ -151,13 +153,13 @@ private function handleRoute($routeInfo, PennyEventInterface $event)
/**
* Handle Response.
*
* @param PennyEvmInterface $eventManager
* @param PennyEventInterface $event
* @param EventManagerInterface $eventManager
* @param EventInterface $event
* @param RouteInfoInterface $routeInfo
*/
private function handleResponse(
PennyEvmInterface $eventManager,
PennyEventInterface $event,
EventManagerInterface $eventManager,
EventInterface $event,
RouteInfoInterface $routeInfo
) {
$eventManager->attach($event->getName(), function ($event) use ($routeInfo) {
Expand All @@ -177,16 +179,16 @@ private function handleResponse(
/**
* Event Manager trigger with exception
*
* @param PennyEvmInterface $eventManager
* @param PennyEventInterface $event
* @param EventManagerInterface $eventManager
* @param EventInterface $event
* @param string $name
* @param Exception $exception
*
* @return PennyEventInterface
* @return EventInterface
*/
private function triggerWithException(
PennyEvmInterface $eventManager,
PennyEventInterface $event,
EventManagerInterface $eventManager,
EventInterface $event,
$name,
Exception $exception
) {
Expand Down
4 changes: 2 additions & 2 deletions src/Event/CakeEvmProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Cake\Event\Event as BaseCakeEvent;
use Cake\Event\EventManager;

class CakeEvmProxy implements PennyEvmInterface
class CakeEvmProxy implements EventManagerInterface
{
/**
* @var EventManager
Expand All @@ -22,7 +22,7 @@ public function __construct()
/**
* {@inheritDoc}
*/
public function trigger(PennyEventInterface $event)
public function trigger(EventInterface $event)
{
if ($event instanceof BaseCakeEvent) {
$this->eventManager->dispatch($event);
Expand Down
2 changes: 1 addition & 1 deletion src/Event/CakeHttpFlowEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Cake\Event\Event as BaseCakeEvent;
use Penny\Route\RouteInfoInterface;

class CakeHttpFlowEvent extends BaseCakeEvent implements PennyEventInterface
class CakeHttpFlowEvent extends BaseCakeEvent implements EventInterface
{
/**
* Representation of an outgoing, client-side request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Exception;
use Penny\Route\RouteInfoInterface;

interface PennyEventInterface
interface EventInterface
{
public function getName();
public function setName($name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
namespace Penny\Event;

interface PennyEvmInterface
interface EventManagerInterface
{
/**
* Triggerer event
*
* @param PennyEventInterface $event Trigger specific event
* @param EventInterface $event Trigger specific event
*/
public function trigger(PennyEventInterface $event);
public function trigger(EventInterface $event);

/**
* Attach new listener at specific event
Expand Down
4 changes: 2 additions & 2 deletions src/Event/ZendEvmProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Zend\EventManager\EventInterface as ZendEventInterface;
use Zend\EventManager\EventManager;

class ZendEvmProxy implements PennyEvmInterface
class ZendEvmProxy implements EventManagerInterface
{
/**
* @var EventManager
Expand All @@ -22,7 +22,7 @@ public function __construct()
/**
* {@inheritDoc}
*/
public function trigger(PennyEventInterface $event)
public function trigger(EventInterface $event)
{
if ($event instanceof ZendEventInterface) {
$this->eventManager->trigger($event);
Expand Down
2 changes: 1 addition & 1 deletion src/Event/ZendHttpFlowEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Penny\Route\RouteInfoInterface;
use Zend\EventManager\Event;

class ZendHttpFlowEvent extends Event implements PennyEventInterface
class ZendHttpFlowEvent extends Event implements EventInterface
{
/**
* Representation of an outgoing, client-side request.
Expand Down
10 changes: 5 additions & 5 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Interop\Container\ContainerInterface;
use Penny\App;
use Penny\Container;
use Penny\Event\PennyEventInterface;
use Penny\Event\PennyEvmInterface;
use Penny\Event\EventInterface;
use Penny\Event\EventManagerInterface;
use Penny\Exception\MethodNotAllowedException;
use Penny\Exception\RouteNotFoundException;
use Penny\Config\Loader;
Expand Down Expand Up @@ -203,7 +203,7 @@ public function testWithInternalContainerFactory()
$this->assertEquals(200, $response->getStatusCode());
}

public function testHttpFlowEventNotInstanceOfPennyEventInterface()
public function testHttpFlowEventNotInstanceOfEventInterface()
{
$this->setExpectedException('RuntimeException');

Expand All @@ -230,8 +230,8 @@ public function testRouteInfoNotInstanceOfRouteInfoInterface()
$dispatcher = function () use ($request) {
return 'callback';
};
$httpFlowEvent = $this->prophesize(PennyEventInterface::class);
$eventManager = $this->prophesize(PennyEvmInterface::class);
$httpFlowEvent = $this->prophesize(EventInterface::class);
$eventManager = $this->prophesize(EventManagerInterface::class);

$container->has('router')->willReturn(true);
$container->get('http_flow_event')->willReturn($httpFlowEvent);
Expand Down

0 comments on commit 25ac241

Please sign in to comment.