private function dispatch($eventName, $controller = null, $type = self::MASTER_REQUEST, $stopWithResponse = true)
    {
        if (null === $this->application) {
            return;
        }

        if (null !== $this->application->getEventDispatcher()) {
            $event = new GetResponseEvent(null === $controller ? $this : $controller, $this->getRequest(), $type);
            $this->application->getEventDispatcher()->dispatch($eventName, $event);

            if ($stopWithResponse && $event->hasResponse()) {
                $this->send($event->getResponse());
            }
        }
    }