Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 2 commits into from

2 participants

@olegstepura

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)

@fabpot fabpot referenced this pull request from a commit
@fabpot fabpot 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
6e3cccb
@fabpot fabpot merged commit 804f63f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 8, 2012
  1. Use single variable for reflection class instance

    Oleg Stepura authored
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 5 deletions.
  1. +11 −5 Templating/TemplateGuesser.php
View
16 Templating/TemplateGuesser.php
@@ -71,12 +71,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));
}
Something went wrong with that request. Please try again.