public static function locateResource($path, ContainerBuilder $container)
    {
        if (0 === stripos($path, '@')) {
            // Treat as a bundle path, e.g. @SomeBundle/path/to/something.

            // Correct backslashed paths.
            $path = str_replace('\\', '/', $path);

            $parts = explode('/', $path);
            $bundle = array_shift($parts);

            $bundleName = str_replace('@', '', $bundle);
            $bundleClass = null;
            foreach ($container->getParameter('kernel.bundles') as $name => $class) {
                if ($name === $bundleName) {
                    $bundleClass = $class;
                    break;
                }
            }

            if (null === $bundleClass) {
                throw new \RuntimeException(sprintf('Unable to find a bundle named "%s" for resource path "%s"', $bundleName, $path));
            }

            $refl = new \ReflectionClass($bundleClass);
            $bundleDir = dirname($refl->getFileName());
            return sprintf('%s/%s', $bundleDir, implode('/', $parts));
        }
        return $path;
    }