Skip to content

Commit

Permalink
Tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Aug 30, 2015
1 parent 44227ec commit 12feaa5
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ language: php
php:
- 5.5
- 5.6
- 7
- 7.0
- hhvm

before_script:
Expand Down
Empty file modified LICENSE
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions Makefile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# customization

PACKAGE_NAME = ICanBoogie/Event
PACKAGE_VERSION = 1.4.x-dev
PACKAGE_NAME = icanboogie/event
PACKAGE_VERSION = 1.4.0

# do not edit the following lines

Expand Down
29 changes: 15 additions & 14 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Code Coverage](https://img.shields.io/coveralls/ICanBoogie/Event/master.svg)](https://coveralls.io/r/ICanBoogie/Event)
[![Packagist](https://img.shields.io/packagist/dt/icanboogie/event.svg)](https://packagist.org/packages/icanboogie/event)

The API provided by the Event package allows developers to provide hooks which other developers
This package allows developers to provide hooks which other developers
may hook into, to be notified when certain events occur inside the application and take action.

Inside [ICanBoogie][], events are often used to alter initial parameters,
Expand Down Expand Up @@ -42,19 +42,19 @@ hooks.
Consider the following class hierarchy:

ICanBoogie\Operation
└─ ICanBoogie\SaveOperation
└─ Icybee\Modules\Node\SaveOperation
└─ Icybee\Modules\Content\SaveOperation
└─ Icybee\Modules\News\SaveOperation
└─ ICanBoogie\Module\Operation\SaveOperation
└─ Icybee\Modules\Node\Operation\SaveOperation
└─ Icybee\Modules\Content\Operation\SaveOperation
└─ Icybee\Modules\News\Operation\SaveOperation


When the `process` event is fired upon a `Icybee\Modules\News\SaveOperation` instance, all event
When the `process` event is fired upon a `…\News\Operation\SaveOperation` instance, all event
hooks attached to the classes for this event are called, starting from the event hooks attached
to the instance class (`Icybee\Modules\News\SaveOperation`) all the way up to those attached
to the instance class (`…\News\Operation\SaveOperation`) all the way up to those attached
to its root class.

Thus, event hooks attached to the `Icybee\Modules\Node\SaveOperation` class are called
when the `process` event is fired upon a `Icybee\Modules\News\SaveOperation` instance. One could
Thus, event hooks attached to the `…\Node\Operation\SaveOperation` class are called
when the `process` event is fired upon a `…\News\Operation\SaveOperation` instance. One could
consider that event hooks are _inherited_.


Expand All @@ -68,10 +68,11 @@ to provide contextual information about an event to the event hooks processing i
the first argument, with the target object as second argument (if any). This instance contain
information directly relating to the type of event they accompany.

For example, a `process` event is usually accompanied by a `ProcessEvent` instance, and a
`process:before` event—fired before a `process` event—is usually accompanied by
a `BeforeProcessEvent` instance. Here after is the definition of the `ProcessEvent` class for the
`process` event type, which is fired on `ICanBoogie\Operation` instances:
For example, a `process` event is usually instantiated from a `ProcessEvent` class, and a
`process:before` event—fired before a `process` event—is usually instantiated
from a `BeforeProcessEvent` instance.

The following code demonstrates how a `ProcessEvent` class may be defined for a `process` event type:

```php
<?php
Expand Down Expand Up @@ -181,7 +182,7 @@ The class name should match the event type. `ProcessEvent` for the `process` eve

## Firing events

Events are fired simply by instantiating an event class.
Events are fired as they are instantiated.

The following example demonstrates how the `process` event is fired upon an
`ICanBoogie\Operation` instance:
Expand Down
Empty file modified composer.json
100755 → 100644
Empty file.
Empty file modified lib/Event.php
100755 → 100644
Empty file.
10 changes: 6 additions & 4 deletions lib/EventCollection.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static public function get()
/**
* Resolves type and hook.
*
* @param string $type_or_hook
* @param string|callable $type_or_hook
* @param callable|null $hook
*
* @return array Returns the type and hook.
Expand Down Expand Up @@ -139,14 +139,14 @@ protected function revoke_traces()
* <pre>
* <?php
*
* $events->attach(function(ICanBoogie\Operation\BeforeProcessEvent $event, ICanBoogie\SaveOperation $target) {
* $events->attach(function(ICanBoogie\Operation\BeforeProcessEvent $event, ICanBoogie\Module\Operation\SaveOperation $target) {
*
* // …
*
* });
* </pre>
*
* The hook will be attached to the `ICanBoogie\SaveOperation::process:before` event.
* The hook will be attached to the `ICanBoogie\Module\Operation\SaveOperation::process:before` event.
*
* @param string|callable $type_or_hook Event type or event hook.
* @param callable $hook The event hook, or nothing if $type is the event hook.
Expand Down Expand Up @@ -246,7 +246,7 @@ public function once($type_or_hook, $hook = null)
{
list($type, $hook) = self::resolve_type_and_hook($type_or_hook, $hook);

return $eh = $this->attach($type, function($e, $t) use ($hook, &$eh) {
$eh = $this->attach($type, function($e, $t) use ($hook, &$eh) {

/* @var $eh EventHook */

Expand All @@ -255,6 +255,8 @@ public function once($type_or_hook, $hook = null)
$eh->detach();

});

return $eh;
}

/**
Expand Down
Empty file modified phpunit.xml.dist
100755 → 100644
Empty file.
11 changes: 0 additions & 11 deletions tests/EventTest.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@

namespace ICanBoogie;

use ICanBoogie\EventTest\CallableInstance;
use ICanBoogie\EventTest\Hooks;
use ICanBoogie\EventTest\Target;

use ICanBoogie\EventTest\A;
use ICanBoogie\EventTest\AttachTo;
use ICanBoogie\EventTest\B;
use ICanBoogie\EventTest\BeforeProcessEvent;
use ICanBoogie\EventTest\ProcessEvent;
Expand Down Expand Up @@ -242,14 +239,6 @@ protected function process(array $values)
}
}

class Attach
{
static public function hook_callback(Dispatcher\BeforeDispatchEvent $event, Dispatcher $target)
{

}
}

/**
* Event class for the `Test\A::validate` event.
*/
Expand Down
17 changes: 0 additions & 17 deletions tests/EventTest/AttachTo.php

This file was deleted.

22 changes: 0 additions & 22 deletions tests/EventTest/AttachTo/ExampleEvent.php

This file was deleted.

6 changes: 2 additions & 4 deletions tests/bootstrap.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

namespace ICanBoogie;

/* @var $loader \Composer\Autoload\ClassLoader */

$loader = require __DIR__ . '/../vendor/autoload.php';
$loader->addPsr4('ICanBoogie\\EventTest\\', __DIR__ . '/EventTest/');
$autoload = require __DIR__ . '/../vendor/autoload.php';
$autoload->addPsr4('ICanBoogie\\EventTest\\', __DIR__ . '/EventTest/');

namespace ICanBoogie\EventTest;

Expand Down

0 comments on commit 12feaa5

Please sign in to comment.