public static function onApplicationStop(Event $event)
    {
        $container = $event->getTarget()->getContainer();
        $eventDispatcher = $container->has('event.dispatcher') ? $container->get('event.dispatcher') : null;

        foreach (array_keys($container->findTaggedServiceIds('bundle')) as $bundleId) {
            if (!$container->hasInstanceOf($bundleId)) {
                continue;
            }

            $bundle = $container->get($bundleId);
            $bundle->stop();

            if (null !== $eventDispatcher) {
                $eventDispatcher->dispatch(
                    sprintf('bundle.%s.stopped', $bundleId),
                    new BundleStopEvent($container->get($bundleId))
                );
            }
        }
    }