Skip to content

Commit

Permalink
Changed interface and re-implement by trait script
Browse files Browse the repository at this point in the history
  • Loading branch information
oanhnn committed Jan 29, 2016
1 parent 879bad2 commit 107d2de
Show file tree
Hide file tree
Showing 16 changed files with 793 additions and 474 deletions.
2 changes: 1 addition & 1 deletion .php_cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$header = <<<EOF
This file is part of `lemon/event` project.
This file is part of `lemonphp/event` project.
(c) 2015-2016 LemonPHP Team
Expand Down
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,47 @@ v1.0.0 - YYYY-MM-DD
#### Removed
- Nothing

v0.3.0 - 2016-01-29
---
#### Changed
- Changed interface `DispatcherInterface` to `EventDispatcherInterface`
- Changed class `Dispatcher` to `EventDispatcher`
- Renamed method `Event::getName()` to `Event::getEventName()`

#### Added
- More test cases
- Trait `EventDispatcherAwareTrait`
- Interface `EventSubscriberInteface`
- Method `EventDispatherInterface::addSubscriber()` and `EventDispatherInterface::removeSubscriber()`

#### Deprecated
- Nothing

#### Fixed
- Nothing

#### Removed
- Nothing

v0.2.0 - 2016-01-22
---
#### Changed
- Changed package namespace from `LemonPHP\Event` to `Lemon\Event`
- Changed signature of method `DispatcherInterface::trigger()`
- Renamed method `Event::getName()` to `Event::getEventName()`

#### Added
- Test classes
- Configure files: `.php_cs`, `.travis.yml`

#### Deprecated
- Nothing

#### Fixed
- Nothing

#### Removed
- Nothing

v0.1.0 - 2015-12-30
---
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ Usage

```
use Lemon\Event\Event;
use Lemon\Event\Dispatcher;
use Lemon\Event\EventDispatcher;
$dispatcher = new Dispatcher();
$dispatcher = new EventDispatcher();
$dispatcher->on('event.name', function(Event $event) {
echo $event->getName() . ' is fired';
// Add listener (listener is callable with event object as argument)
$dispatcher->addListener('event.type', function(Event $event) {
echo $event->getEventType() . ' is fired';
});
$dispatcher->trigger('event.name');
// Add subscriber (subscriber is implemented by yourself)
$dispatcher->addSubscriber($subscriber);
$dispatcher->dispatch('event.type');
```

Changelog
Expand Down
158 changes: 0 additions & 158 deletions src/Dispatcher.php

This file was deleted.

60 changes: 0 additions & 60 deletions src/DispatcherInterface.php

This file was deleted.

27 changes: 20 additions & 7 deletions src/Event.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* This file is part of `lemon/event` project.
* This file is part of `lemonphp/event` project.
*
* (c) 2015-2016 LemonPHP Team
*
Expand All @@ -11,24 +11,35 @@

namespace Lemon\Event;

/**
* Event is the base class for classes containing event data.
*
* This class contains no event data. It is used by events that do not pass
* state information to an event handler when an event is raised.
*
* You can call the method stopPropagation() to abort the execution of
* further listeners in your event listener.
*/
class Event
{
/**
* Event type
*
* @var string Read only property
*/
protected $eventName;
protected $eventType;

/**
* @var bool Whether no further event listeners should be triggered
*/
protected $stopped = false;

/**
* @param string $name
* @param string $type
*/
public function __construct($name)
public function __construct($type)
{
$this->eventName = (string) $name;
$this->eventType = (string) $type;
}

/**
Expand All @@ -55,10 +66,12 @@ public function stopPropagation()
}

/**
* Get event type
*
* @return string
*/
public function getEventName()
public function getEventType()
{
return $this->eventName;
return $this->eventType;
}
}
24 changes: 24 additions & 0 deletions src/EventDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of `lemonphp/event` project.
*
* (c) 2015-2016 LemonPHP Team
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Lemon\Event;

/**
* The EventDispatcher is the central point of Symfony's event listener system.
*
* Listeners are registered on the manager and events are dispatched through the
* manager.
*/
class EventDispatcher implements EventDispatcherInterface
{

use EventDispatcherAwareTrait;
}
Loading

0 comments on commit 107d2de

Please sign in to comment.