Browse files

merged branch olegstepura/patch-1 (PR #104)

Commits
-------

804f63f Use single variable for reflection class instance
7a0c7c0 Make Template guesser look at parent classes for bundle

Discussion
----------

Make Template guesser look at parent classes for bundle (The better way)

Solves the same issue as this pull request: #98

but is a better way to do that - inside getBundleForClass() method and without catching exceptions (which must be slower and would be the default behavior for all secured via annotations controllers with the latest JMSSecurityExtraBundle)

---------------------------------------------------------------------------

by olegstepura at 2012-03-08T22:28:31Z

Fixes symfony/symfony-standard#285 after applying symfony/symfony-standard#275
  • Loading branch information...
2 parents 04f6c8f + 804f63f commit 6e3cccb66d3577fdbd5b6935a5d6b8bed8d47768 @fabpot fabpot committed Mar 18, 2012
Showing with 11 additions and 5 deletions.
  1. +11 −5 Templating/TemplateGuesser.php
View
16 Templating/TemplateGuesser.php
@@ -80,12 +80,18 @@ public function guessTemplateName($controller, Request $request, $engine = 'twig
*/
protected function getBundleForClass($class)
{
- $namespace = strtr(dirname(strtr($class, '\\', '/')), '/', '\\');
- foreach ($this->kernel->getBundles() as $bundle) {
- if (0 === strpos($namespace, $bundle->getNamespace())) {
- return $bundle;
+ $reflectionClass = new \ReflectionClass($class);
+ $bundles = $this->kernel->getBundles();
+
+ do {
+ $namespace = $reflectionClass->getNamespaceName();
+ foreach ($bundles as $bundle) {
+ if (0 === strpos($namespace, $bundle->getNamespace())) {
+ return $bundle;
+ }
}
- }
+ $reflectionClass = $reflectionClass->getParentClass();
+ } while ($reflectionClass);
throw new \InvalidArgumentException(sprintf('The "%s" class does not belong to a registered bundle.', $class));
}

0 comments on commit 6e3cccb

Please sign in to comment.