public function dispatchEvent(DispatcherInterface $dispatcher, $name, \ArrayAccess $context = null)
{
if ($this->dispatcher) {
throw new \RuntimeException('Event dispatching is still running!');
} else {
if ($this->currentState->hasEvent($name)) {
$this->acquireLockOrThrowException();
$this->dispatcher = $dispatcher;
if ($context) {
$this->currentContext = $context;
} else {
$this->currentContext = new \ArrayIterator(array());
}
$this->currentEvent = $this->currentState->getEvent($name);
$dispatcher->dispatch($this->currentEvent, array($this->subject, $this->currentContext), new Callback(array($this, 'onDispatcherReady')));
} else {
throw new WrongEventForStateException($this->currentState->getName(), $name);
}
}
}