diff --git a/src/Symfony/Framework/Kernel.php b/src/Symfony/Framework/Kernel.php index 57184473a3..c89b6aa821 100644 --- a/src/Symfony/Framework/Kernel.php +++ b/src/Symfony/Framework/Kernel.php @@ -252,6 +252,23 @@ abstract class Kernel implements HttpKernelInterface, \Serializable return false; } + /** + * Returns the Bundle name for a given class. + * + * @param string $class A class name + * + * @return string The Bundle name or null if the class does not belongs to a bundle + */ + public function getBundleForClass($class) + { + $namespace = substr($class, 0, strrpos($class, '\\')); + foreach (array_keys($this->getBundleDirs()) as $prefix) { + if (0 === $pos = strpos($namespace, $prefix)) { + return substr($namespace, strlen($prefix) + 1, strpos($class, 'Bundle\\') + 7); + } + } + } + public function getName() { return $this->name;