Skip to content

Commit

Permalink
update to hhvm 4.56 and contract 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
azjezz committed May 9, 2020
1 parent 35a28c3 commit 56ad545
Show file tree
Hide file tree
Showing 25 changed files with 61 additions and 205 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ os:
- linux

env:
- HHVM_VERSION=4.25-latest
- HHVM_VERSION=4.30-latest
- HHVM_VERSION=4.56-latest
- HHVM_VERSION=latest
- HHVM_VERSION=nightly

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
}
],
"require": {
"hhvm": "^4.25",
"hhvm/hsl": "^4.25",
"his/container": "^0.1"
"hhvm": "^4.56",
"hhvm/hsl": "^4.40",
"nuxed/contract": "^1.1"
},
"require-dev": {
"facebook/fbexpect": "^2.7",
Expand All @@ -33,4 +33,4 @@
"test": "hacktest tests/",
"type-check": "hh_client src/"
}
}
}
32 changes: 0 additions & 32 deletions src/Nuxed/EventDispatcher/Event/ErrorEvent.hack

This file was deleted.

10 changes: 0 additions & 10 deletions src/Nuxed/EventDispatcher/Event/IEvent.hack

This file was deleted.

22 changes: 0 additions & 22 deletions src/Nuxed/EventDispatcher/Event/IStoppableEvent.hack

This file was deleted.

44 changes: 9 additions & 35 deletions src/Nuxed/EventDispatcher/EventDispatcher.hack
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
namespace Nuxed\EventDispatcher;

use namespace HH\Lib;
use namespace Nuxed\EventDispatcher\{Event, EventListener};

final class EventDispatcher implements IEventDispatcher {
use namespace Nuxed\Contract\EventDispatcher;
use namespace Nuxed\Contract\EventDispatcher\{
Event,
EventListener,
ListenerProvider,
};

final class EventDispatcher implements EventDispatcher\IEventDispatcher {
public function __construct(
private ListenerProvider\IListenerProvider $listenerProvider,
) {}

/**
* Provide all relevant listeners with an event to process.
*
* If a Throwable is caught when executing the listener loop, it is cast
* to an ErrorEvent, and then the method calls itself with that instance,
* re-throwing the original Throwable on completion.
*
* In the case that a Throwable is caught for an ErrorEvent, we re-throw
* to prevent recursion.
*
* @template T as IEvent
*
* @return T The Event that was passed, now modified by listeners.
Expand Down Expand Up @@ -46,35 +44,11 @@ final class EventDispatcher implements IEventDispatcher {
return;
}

try {
await $listener->process($event);
} catch (\Exception $e) {
if ($event is Event\ErrorEvent<_>) {
throw new Exception\InvalidListenerException('');
throw $event->getException();
}

await $this->handleCaughtException<T>($e, $event, $listener);
}
await $listener->process($event);
};
}

await $lastOperation;
return $event;
}

private async function handleCaughtException<
<<__Enforceable>> reify T as Event\IEvent,
>(
\Exception $e,
T $event,
EventListener\IEventListener<T> $listener,
): Awaitable<noreturn> {
await $this->dispatch<Event\ErrorEvent<T>>(
new Event\ErrorEvent<T>($event, $listener, $e),
);

// Re-throw the original exception, per the spec.
throw $e;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace Nuxed\EventDispatcher\EventListener;

use namespace Nuxed\EventDispatcher\Event;
use namespace Nuxed\Contract\EventDispatcher\{Event, EventListener};

/**
* Decorator defines a callable listener for an event.
*/
final class CallableEventListener<T as Event\IEvent>
implements IEventListener<T> {
implements EventListener\IEventListener<T> {
public function __construct(
private (function(T): Awaitable<void>) $listener,
) {}
Expand Down
13 changes: 0 additions & 13 deletions src/Nuxed/EventDispatcher/EventListener/IEventListener.hack

This file was deleted.

4 changes: 2 additions & 2 deletions src/Nuxed/EventDispatcher/EventListener/callable.hack
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Nuxed\EventDispatcher\EventListener;

use namespace Nuxed\EventDispatcher\Event;
use namespace Nuxed\Contract\EventDispatcher\{Event, EventListener};

/**
* Helper function to create an event listener,
Expand All @@ -10,6 +10,6 @@ use namespace Nuxed\EventDispatcher\Event;
*/
function callable<T as Event\IEvent>(
(function(T): Awaitable<void>) $listener,
): IEventListener<T> {
): EventListener\IEventListener<T> {
return new CallableEventListener($listener);
}
14 changes: 7 additions & 7 deletions src/Nuxed/EventDispatcher/EventListener/lazy.hack
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
namespace Nuxed\EventDispatcher\EventListener;

use namespace His\Container;
use namespace Nuxed\EventDispatcher\Event;
use namespace Nuxed\Contract\EventDispatcher\{Event, EventListener};
use namespace Nuxed\Contract\Container;

/**
* Helper function to create a lazy loaded event listener.
*/
function lazy<T as Event\IEvent>(
Container\ContainerInterface $container,
classname<IEventListener<T>> $service,
): IEventListener<T> {
Container\IContainer $container,
classname<EventListener\IEventListener<T>> $service,
): EventListener\IEventListener<T> {
return callable<T>(
(T $event) ==>
$container->get<IEventListener<T>>($service)->process($event),
(T $event) ==> $container->get<EventListener\IEventListener<T>>($service)
->process($event),
);
}
15 changes: 0 additions & 15 deletions src/Nuxed/EventDispatcher/IEventDispatcher.hack

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Nuxed\EventDispatcher\ListenerProvider;

use namespace HH\Lib\C;
use namespace Nuxed\EventDispatcher\{Event, EventListener};
use namespace Nuxed\Contract\EventDispatcher\{Event, EventListener};

/**
* The `AttachableListenerProvider` is a built-in implementation for `IAttachableListenerProvider`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
namespace Nuxed\EventDispatcher\ListenerProvider;

use namespace Nuxed\EventDispatcher\{Event, EventListener};
use namespace Nuxed\Contract\EventDispatcher\{
Event,
EventListener,
ListenerProvider,
};

/**
* The `IAttachableListenerProvider` listener provider allows you to attach event listeners,
* to the provider after construction.
*
* Event listeners returned by `getListener($event)`, will be in the same order they were added in.
*
* @see Nuxed\EventDispatcher\ListenerProvider\IListenerProvider::getListeners()
* @see Nuxed\Contract\EventDispatcher\ListenerProvider\IListenerProvider::getListeners()
*/
interface IAttachableListenerProvider extends IListenerProvider {
interface IAttachableListenerProvider
extends ListenerProvider\IListenerProvider {
/**
* Attach a listener to the given event.
*/
Expand Down
21 changes: 0 additions & 21 deletions src/Nuxed/EventDispatcher/ListenerProvider/IListenerProvider.hack

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace Nuxed\EventDispatcher\ListenerProvider;

use namespace Nuxed\EventDispatcher\{Event, EventListener};
use namespace Nuxed\Contract\EventDispatcher\{Event, EventListener};

/**
* The `IPrioritizedListenerProvider` listener provider allows you to attach event listeners,
* to the provider after construction, with a given priority.
*
* Event listeners returned by `getListener($event)`, will be in the ordered by priority.
*
* @see Nuxed\EventDispatcher\ListenerProvider\IListenerProvider::getListeners()
* @see Nuxed\Contract\EventDispatcher\ListenerProvider\IListenerProvider::getListeners()
*/
interface IPrioritizedListenerProvider extends IAttachableListenerProvider {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
namespace Nuxed\EventDispatcher\ListenerProvider;

use namespace Nuxed\EventDispatcher\{Event, EventListener};
use namespace Nuxed\Contract\EventDispatcher\{
Event,
EventListener,
ListenerProvider,
};

/**
* The `IReifiedListenerProvider` uses reified generics features to determine the event type,
* instead of recieving it as an argument.
*
* @see Nuxed\EventDispatcher\ListenerProvider\IListenerProvider::getListeners()
* @see Nuxed\Contract\EventDispatcher\ListenerProvider\IListenerProvider::getListeners()
*/
interface IReifiedListenerProvider extends IListenerProvider {
interface IReifiedListenerProvider extends ListenerProvider\IListenerProvider {
/**
* Attach a listener
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
namespace Nuxed\EventDispatcher\ListenerProvider;

use namespace Nuxed\EventDispatcher\{Event, EventListener};
use namespace Nuxed\Contract\EventDispatcher\{
Event,
EventListener,
ListenerProvider,
};

/**
* The `ListenerProviderAggregate` allows you to combine multiple listener providers,
* to use with the same event dispatcher.
*
* @see Nuxed\EventDispatcher\ListenerProviderAggregate::attach()
*/
final class ListenerProviderAggregate implements IListenerProvider {
private vec<IListenerProvider> $providers = vec[];
final class ListenerProviderAggregate
implements ListenerProvider\IListenerProvider {
private vec<ListenerProvider\IListenerProvider> $providers = vec[];

/**
* {@inheritdoc}
Expand All @@ -27,7 +32,7 @@ final class ListenerProviderAggregate implements IListenerProvider {
/**
* Attach a listener provider to the listeners aggregate.
*/
public function attach(IListenerProvider $provider): void {
public function attach(ListenerProvider\IListenerProvider $provider): void {
$this->providers[] = $provider;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Nuxed\EventDispatcher\ListenerProvider;

use namespace HH\Lib\{C, Str, Vec};
use namespace Nuxed\EventDispatcher\{Event, EventListener};
use namespace Nuxed\Contract\EventDispatcher\{Event, EventListener};

/**
* The `PrioritizedListenerProvider` is a built-in implementation for `IPrioritizedListenerProvider`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Nuxed\EventDispatcher\ListenerProvider;

use namespace HH\Lib\{C, Vec};
use namespace Nuxed\EventDispatcher\{Event, EventListener};
use namespace Nuxed\Contract\EventDispatcher\{Event, EventListener};

/**
* The `RandomizedListenerProvider` is a built-in implementation for `IRandomizedListenerProvider`
Expand Down

0 comments on commit 56ad545

Please sign in to comment.