Переглянути джерело

[FrameworkBundle] fixed controller names conversion when a bundle is defined in two different namespaces

Fabien Potencier 14 роки тому
батько
коміт
38cbc610e9

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameConverter.php

@@ -101,7 +101,7 @@ class ControllerNameConverter
         foreach ($this->namespaces as $namespace) {
             $prefix = null;
             foreach ($this->kernel->getBundles() as $b) {
-                if ($bundle === $b->getName()) {
+                if ($bundle === $b->getName() && 0 === strpos($b->getNamespace(), $namespace)) {
                     $prefix = $b->getNamespace();
 
                     break;

+ 2 - 2
src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameConverterTest.php

@@ -68,14 +68,14 @@ class ControllerNameConverterTest extends TestCase
         $converter = new ControllerNameConverter($kernel, $logger);
 
         $this->assertEquals('TestBundle\FooBundle\Controller\DefaultController::indexAction', $converter->fromShortNotation('FooBundle:Default:index'), '->fromShortNotation() converts a short a:b:c notation string to a class::method string');
-        $this->assertEquals('TestBundle\Sensio\FooBundle\Controller\DefaultController::indexAction', $converter->fromShortNotation('SensioFooBundle:Default:index'), '->fromShortNotation() converts a short a:b:c notation string to a class::method string');
+        $this->assertEquals('TestApplication\Sensio\FooBundle\Controller\DefaultController::indexAction', $converter->fromShortNotation('SensioFooBundle:Default:index'), '->fromShortNotation() converts a short a:b:c notation string to a class::method string');
         $this->assertEquals('TestBundle\Sensio\Cms\FooBundle\Controller\DefaultController::indexAction', $converter->fromShortNotation('SensioCmsFooBundle:Default:index'), '->fromShortNotation() converts a short a:b:c notation string to a class::method string');
 
         try {
             $converter->fromShortNotation('foo:');
             $this->fail('->fromShortNotation() throws an \InvalidArgumentException if the controller is not an a:b:c string');
         } catch (\Exception $e) {
-            $this->assertInstanceOf('\InvalidArgumentException', $e, '->toShortNotation() throws an \InvalidArgumentException if the controller is not an a:b:c string');
+            $this->assertInstanceOf('\InvalidArgumentException', $e, '->fromShortNotation() throws an \InvalidArgumentException if the controller is not an a:b:c string');
         }
 
         try {

+ 21 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestApplication/Sensio/FooBundle/Controller/DefaultController.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace TestApplication\Sensio\FooBundle\Controller;
+
+/*
+ * This file is part of the Symfony framework.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * DefaultController.
+ *
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ */
+class DefaultController
+{
+}

+ 23 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestApplication/Sensio/FooBundle/SensioFooBundle.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace TestApplication\Sensio\FooBundle;
+
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+
+/*
+ * This file is part of the Symfony framework.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+/**
+ * Bundle.
+ *
+ * @author Fabien Potencier <fabien.potencier@symfony-project.com>
+ */
+class SensioFooBundle extends Bundle
+{
+}

+ 4 - 1
src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php

@@ -33,7 +33,8 @@ class Kernel extends BaseKernel
 
         $loader = new UniversalClassLoader();
         $loader->registerNamespaces(array(
-            'TestBundle' => __DIR__.'/Fixtures/',
+            'TestBundle'      => __DIR__.'/Fixtures/',
+            'TestApplication' => __DIR__.'/Fixtures/',
         ));
         $loader->register();
     }
@@ -55,6 +56,7 @@ class Kernel extends BaseKernel
             new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
             new \TestBundle\FooBundle\FooBundle(),
             new \TestBundle\Sensio\FooBundle\SensioFooBundle(),
+            new \TestApplication\Sensio\FooBundle\SensioFooBundle(),
             new \TestBundle\Sensio\Cms\FooBundle\SensioCmsFooBundle(),
         );
     }
@@ -64,6 +66,7 @@ class Kernel extends BaseKernel
         return array(
             'Application'     => __DIR__.'/../src/Application',
             'Bundle'          => __DIR__.'/../src/Bundle',
+            'TestApplication' => __DIR__.'/Fixtures/TestApplication',
             'TestBundle'      => __DIR__.'/Fixtures/TestBundle',
             'Symfony\\Bundle' => __DIR__.'/../src/vendor/symfony/src/Symfony/Bundle',
         );