public function attachHandler(callable $handler, $key = null)
    {
        if ($key !== null) {
            $this->eventHandlers[$key] = $handler;
        } else {
            $this->eventHandlers[] = $handler;
        }
    }