Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/trigger-listeners'
Browse files Browse the repository at this point in the history
Close #125
  • Loading branch information
weierophinney committed Aug 3, 2016
2 parents fa2b6f0 + 3a88f96 commit 3c15ae4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 1.4.2 - TBD
## 1.4.2 - 2016-08-03

### Added

Expand All @@ -18,7 +18,10 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#125](https://github.com/zfcampus/zf-mvc-auth/pull/125) updates the
`MvcRouteListener` to trigger events using `triggerEventUntil()` instead
of using argument overloading on `trigger()`; this change ensures that the
code will work with zend-eventmanager v3 properly.

## 1.4.1 - 2016-07-25

Expand Down
36 changes: 22 additions & 14 deletions src/MvcRouteListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ public function authentication(MvcEvent $mvcEvent)
}

$mvcAuthEvent = $this->mvcAuthEvent;
$responses = $this->events->trigger($mvcAuthEvent::EVENT_AUTHENTICATION, $mvcAuthEvent, function ($r) {
$mvcAuthEvent->setName($mvcAuthEvent::EVENT_AUTHENTICATION);
$responses = $this->events->triggerEventUntil(function ($r) {
return ($r instanceof Identity\IdentityInterface
|| $r instanceof Result
|| $r instanceof Response
);
});
}, $mvcAuthEvent);

$result = $responses->last();
$storage = $this->authentication->getStorage();
Expand Down Expand Up @@ -148,13 +149,13 @@ public function authenticationPost(MvcEvent $mvcEvent)
return;
}

$responses = $this->events->trigger(
MvcAuthEvent::EVENT_AUTHENTICATION_POST,
$this->mvcAuthEvent,
function ($r) {
return ($r instanceof Response);
}
);
$mvcAuthEvent = $this->mvcAuthEvent;
$mvcAuthEvent->setName($mvcAuthEvent::EVENT_AUTHENTICATION_POST);

$responses = $this->events->triggerEventUntil(function ($r) {
return ($r instanceof Response);
}, $mvcAuthEvent);

return $responses->last();
}

Expand All @@ -172,14 +173,17 @@ public function authorization(MvcEvent $mvcEvent)
return;
}

$responses = $this->events->trigger(MvcAuthEvent::EVENT_AUTHORIZATION, $this->mvcAuthEvent, function ($r) {
$mvcAuthEvent = $this->mvcAuthEvent;
$mvcAuthEvent->setName($mvcAuthEvent::EVENT_AUTHORIZATION);

$responses = $this->events->triggerEventUntil(function ($r) {
return (is_bool($r) || $r instanceof Response);
});
}, $mvcAuthEvent);

$result = $responses->last();

if (is_bool($result)) {
$this->mvcAuthEvent->setIsAuthorized($result);
$mvcAuthEvent->setIsAuthorized($result);
return;
}

Expand All @@ -202,9 +206,13 @@ public function authorizationPost(MvcEvent $mvcEvent)
return;
}

$responses = $this->events->trigger(MvcAuthEvent::EVENT_AUTHORIZATION_POST, $this->mvcAuthEvent, function ($r) {
$mvcAuthEvent = $this->mvcAuthEvent;
$mvcAuthEvent->setName($mvcAuthEvent::EVENT_AUTHORIZATION_POST);

$responses = $this->events->triggerEventUntil(function ($r) {
return ($r instanceof Response);
});
}, $mvcAuthEvent);

return $responses->last();
}
}
2 changes: 1 addition & 1 deletion test/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function createServiceManager(array $config)

// zend-servicemanager v2
$servicesConfig = new ServiceManagerConfig($config['service_manager']);
$services = new ServiceManager($servicesConfig);
return new ServiceManager($servicesConfig);
}

public function testOnBootstrapReturnsEarlyForNonHttpEvents()
Expand Down

0 comments on commit 3c15ae4

Please sign in to comment.