Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken event system #677

Merged
merged 4 commits into from
Aug 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/ZfcUser/Authentication/Adapter/AdapterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Zend\Authentication\Adapter\AdapterInterface;
use Zend\Authentication\Result as AuthenticationResult;
use Zend\EventManager\Event;
use Zend\EventManager\EventInterface;
use Zend\EventManager\EventManagerAwareTrait;
use Zend\Stdlib\RequestInterface as Request;
use Zend\Stdlib\ResponseInterface as Response;
Expand Down Expand Up @@ -51,11 +52,13 @@ public function prepareForAuthentication(Request $request)
$e = $this->getEvent();
$e->setRequest($request);

$this->getEventManager()->trigger('authenticate.pre', $e);
$e->setName('authenticate.pre');
$this->getEventManager()->triggerEvent($e);

$result = $this->getEventManager()->trigger('authenticate', $e, function ($test) {
$e->setName('authenticate');
$result = $this->getEventManager()->triggerEventUntil(function ($test) {
return ($test instanceof Response);
});
}, $e);

if ($result->stopped()) {
if ($result->last() instanceof Response) {
Expand All @@ -71,11 +74,13 @@ public function prepareForAuthentication(Request $request)
}

if ($e->getIdentity()) {
$this->getEventManager()->trigger('authenticate.success', $e);
$e->setName('authenticate.success');
$this->getEventManager()->triggerEvent($e);
return true;
}

$this->getEventManager()->trigger('authenticate.fail', $e);
$e->setName('authenticate.fail');
$this->getEventManager()->triggerEvent($e);

return false;
}
Expand Down Expand Up @@ -109,7 +114,9 @@ public function resetAdapters()
public function logoutAdapters()
{
//Adapters might need to perform additional cleanup after logout
$this->getEventManager()->trigger('logout', $this->getEvent());
$e = $this->getEvent();
$e->setName('logout');
$this->getEventManager()->triggerEvent($e);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AdapterChainServiceFactory implements FactoryInterface
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
{
$chain = new AdapterChain();
$chain->setEventManager($serviceLocator->get('EventManager'));

$options = $this->getOptions($serviceLocator);

Expand Down
4 changes: 2 additions & 2 deletions src/ZfcUser/Authentication/Adapter/ChainableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
interface ChainableAdapter
{
/**
* @param EventInterface $e
* @param AdapterChainEvent $e
* @return bool
*/
public function authenticate(EventInterface $e);
public function authenticate(AdapterChainEvent $e);

/**
* @return StorageInterface
Expand Down
9 changes: 4 additions & 5 deletions src/ZfcUser/Authentication/Adapter/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,19 @@ class Db extends AbstractAdapter

/**
* Called when user id logged out
* @param EventInterface $e
* @param AdapterChainEvent $e
*/
public function logout(EventInterface $e)
public function logout(AdapterChainEvent $e)
{
$this->getStorage()->clear();
}

/**
* @param EventInterface $e
* @param AdapterChainEvent $e
* @return bool
*/
public function authenticate(EventInterface $e)
public function authenticate(AdapterChainEvent $e)
{
$e = $e->getTarget();
if ($this->isSatisfied()) {
$storage = $this->getStorage()->read();
$e->setIdentity($storage['identity'])
Expand Down
2 changes: 1 addition & 1 deletion src/ZfcUser/EventManager/EventProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function setEventManager(EventManagerInterface $events)
public function getEventManager()
{
if (!$this->events instanceof EventManagerInterface) {
$this->setEventManager(new EventManager(new SharedEventManager()));
$this->setEventManager(new EventManager());
}
return $this->events;
}
Expand Down
2 changes: 0 additions & 2 deletions src/ZfcUser/Form/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public function __construct($name = null)
//$csrf = new Element\Csrf('csrf');
//$csrf->getValidator()->setTimeout($this->getRegistrationOptions()->getUserFormTimeout());
//$this->add($csrf);

$this->getEventManager()->trigger('init', $this);
}

public function init()
Expand Down
2 changes: 0 additions & 2 deletions src/ZfcUser/Form/ChangeEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public function __construct($name, AuthenticationOptionsInterface $options)
'type' => 'submit'
),
));

$this->getEventManager()->trigger('init', $this);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/ZfcUser/Form/ChangePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public function __construct($name, AuthenticationOptionsInterface $options)
'type' => 'submit'
),
));

$this->getEventManager()->trigger('init', $this);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/ZfcUser/Form/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public function __construct($name, AuthenticationOptionsInterface $options)
$this->add($submitElement, array(
'priority' => -100,
));

$this->getEventManager()->trigger('init', $this);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/ZfcUser/Form/LoginFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,5 @@ public function __construct(AuthenticationOptionsInterface $options)
array('name' => 'StringTrim'),
),
));

$this->getEventManager()->trigger('init', $this);
}
}
2 changes: 0 additions & 2 deletions src/ZfcUser/Form/RegisterFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ public function __construct($emailValidator, $usernameValidator, RegistrationOpt
),
),
));

$this->getEventManager()->trigger('init', $this);
}

public function getEmailValidator()
Expand Down