Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fab2s committed Mar 31, 2018
1 parent 9233739 commit ed29cb4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/exceptions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Exceptions

When an `Exception` is thrown during execution, NodalFlow catches it, perform few cleanup operations, including triggering the [`FlowEvent::FLOW_FAIL`](events.md#floweventflow_fail) Event and then re-throws it as is if it's a `NodalFlowException` or else throws a `NodalFlowException` with the original exception set as previous. This means that NodalFlow will only throw `NodalFlowException` unless an exception is raised within an exception callback of yours.
When an `Exception` is thrown during execution, NodalFlow catches it, perform few cleanup operations, including triggering the [`FlowEvent::FLOW_FAIL`](events.md#floweventflow_fail) Event and then re-throws it as is if it's a `NodalFlowException` or else throws a `NodalFlowException` with the original exception set as previous. This means that NodalFlow will only throw `NodalFlowException` unless an exception is raised within an exception [event](events.md) of yours.

`NodalFlowException` extends [ContextException](https://github.com/fab2s/ContextException) formalizing a common context exception pattern (as in Symfony for example) to ease `Exception` logging.

Expand Down
16 changes: 7 additions & 9 deletions src/Flows/FlowEventAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,16 @@ protected function triggerEvent($eventName, NodeInterface $node = null)
*/
protected function listActiveEvent($reload = false)
{
if (!isset($this->dispatcher)) {
if (!isset($this->dispatcher) || (isset($this->activeEvents) && !$reload)) {
return $this;
}

if (!isset($this->activeEvents) || $reload) {
$this->activeEvents = [];
$eventList = FlowEvent::getEventList();
$sortedListeners = $this->dispatcher->getListeners();
foreach ($sortedListeners as $eventName => $listeners) {
if (isset($eventList[$eventName]) && !empty($listeners)) {
$this->activeEvents[$eventName] = 1;
}
$this->activeEvents = [];
$eventList = FlowEvent::getEventList();
$sortedListeners = $this->dispatcher->getListeners();
foreach ($sortedListeners as $eventName => $listeners) {
if (isset($eventList[$eventName]) && !empty($listeners)) {
$this->activeEvents[$eventName] = 1;
}
}

Expand Down

0 comments on commit ed29cb4

Please sign in to comment.