From 3ed47114d6d447107e992941b8c866072978ec72 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Sat, 29 Jan 2011 16:28:49 +0100 Subject: [PATCH] [Bundle] Make getPath() less error prone by allowing both backward and forward slashes --- .../CompatAssetsBundle/CompatAssetsBundle.php | 6 ++-- .../Bundle/DoctrineBundle/DoctrineBundle.php | 4 +-- .../AnnotationsBundle/AnnotationsBundle.php | 4 +-- .../AnnotationsBundle/AnnotationsBundle.php | 4 +-- .../Fixtures/Bundles/XmlBundle/XmlBundle.php | 4 +-- .../Bundles/YamlBundle/YamlBundle.php | 4 +-- .../DoctrineMigrationsBundle.php | 4 +-- .../DoctrineMongoDBBundle.php | 4 +-- .../AnnotationsBundle/AnnotationsBundle.php | 4 +-- .../Fixtures/Bundles/XmlBundle/XmlBundle.php | 4 +-- .../Bundles/YamlBundle/YamlBundle.php | 4 +-- .../CacheWarmer/TemplatePathsCacheWarmer.php | 2 +- .../FrameworkBundle/FrameworkBundle.php | 4 +-- .../Fabpot/FooBundle/FabpotFooBundle.php | 4 +-- .../TestBundle/FooBundle/FooBundle.php | 4 +-- .../Cms/FooBundle/SensioCmsFooBundle.php | 4 +-- .../Sensio/FooBundle/SensioFooBundle.php | 4 +-- .../Bundle/SecurityBundle/SecurityBundle.php | 4 +-- .../SwiftmailerBundle/SwiftmailerBundle.php | 4 +-- src/Symfony/Bundle/TwigBundle/TwigBundle.php | 4 +-- .../WebProfilerBundle/WebProfilerBundle.php | 4 +-- src/Symfony/Bundle/ZendBundle/ZendBundle.php | 4 +-- .../Component/HttpKernel/Bundle/Bundle.php | 31 +++++++++++------ .../HttpKernel/Bundle/BundleInterface.php | 6 ++-- src/Symfony/Component/HttpKernel/Kernel.php | 2 +- .../Component/HttpKernel/bootstrap.php | 20 +++++++---- .../Component/HttpKernel/bootstrap_cache.php | 10 ++++-- .../HttpKernel/Bundle/BundleTest.php | 33 +++++++++++++++++++ .../Tests/Component/HttpKernel/KernelTest.php | 6 ++-- 29 files changed, 126 insertions(+), 70 deletions(-) create mode 100644 tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php diff --git a/src/Symfony/Bundle/CompatAssetsBundle/CompatAssetsBundle.php b/src/Symfony/Bundle/CompatAssetsBundle/CompatAssetsBundle.php index ac6a9c55ef..14fca507d9 100644 --- a/src/Symfony/Bundle/CompatAssetsBundle/CompatAssetsBundle.php +++ b/src/Symfony/Bundle/CompatAssetsBundle/CompatAssetsBundle.php @@ -31,8 +31,8 @@ class CompatAssetsBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } -} + diff --git a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php index 36085d0fda..44bacc7883 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php @@ -43,8 +43,8 @@ class DoctrineBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php index 3d615bb9e1..ddd042ff9b 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php @@ -17,8 +17,8 @@ class AnnotationsBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/Vendor/AnnotationsBundle/AnnotationsBundle.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/Vendor/AnnotationsBundle/AnnotationsBundle.php index 9a393487a3..f3b4a70096 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/Vendor/AnnotationsBundle/AnnotationsBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/Vendor/AnnotationsBundle/AnnotationsBundle.php @@ -17,8 +17,8 @@ class AnnotationsBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/XmlBundle.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/XmlBundle.php index f3ab6adfe7..9b9d05cf3e 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/XmlBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/XmlBundle.php @@ -17,8 +17,8 @@ class XmlBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php index 75fa1c3e2d..b1ba3aee7a 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php @@ -17,8 +17,8 @@ class YamlBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/DoctrineMigrationsBundle/DoctrineMigrationsBundle.php b/src/Symfony/Bundle/DoctrineMigrationsBundle/DoctrineMigrationsBundle.php index d85088a5b7..35423cc643 100644 --- a/src/Symfony/Bundle/DoctrineMigrationsBundle/DoctrineMigrationsBundle.php +++ b/src/Symfony/Bundle/DoctrineMigrationsBundle/DoctrineMigrationsBundle.php @@ -32,8 +32,8 @@ class DoctrineMigrationsBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php index 65c87f6aa5..576646204a 100755 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php @@ -47,8 +47,8 @@ class DoctrineMongoDBBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php index 3a0f1f9ec5..0f8c4a91fd 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php @@ -17,8 +17,8 @@ class AnnotationsBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/XmlBundle.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/XmlBundle.php index 24a9ae8c67..eee158c3ec 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/XmlBundle.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/XmlBundle.php @@ -17,8 +17,8 @@ class XmlBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php index cfab143340..4e7de5aedf 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php @@ -17,8 +17,8 @@ class YamlBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php index 032b927804..3477454468 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php @@ -64,7 +64,7 @@ class TemplatePathsCacheWarmer extends CacheWarmer $prefix = '/Resources/views'; $templates = array(); foreach ($this->kernel->getBundles() as $name => $bundle) { - if (!is_dir($dir = $bundle->getPath().$prefix)) { + if (!is_dir($dir = $bundle->getNormalizedPath().$prefix)) { continue; } diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 82faeaa87c..e14b1be848 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -92,8 +92,8 @@ class FrameworkBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Fabpot/FooBundle/FabpotFooBundle.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Fabpot/FooBundle/FabpotFooBundle.php index d2a578b11f..1a70daacdd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Fabpot/FooBundle/FabpotFooBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Fabpot/FooBundle/FabpotFooBundle.php @@ -39,8 +39,8 @@ class FabpotFooBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/FooBundle/FooBundle.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/FooBundle/FooBundle.php index 397e05997d..d602cf89cb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/FooBundle/FooBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/FooBundle/FooBundle.php @@ -31,8 +31,8 @@ class FooBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Sensio/Cms/FooBundle/SensioCmsFooBundle.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Sensio/Cms/FooBundle/SensioCmsFooBundle.php index 0440ee03d0..49bdf9a08b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Sensio/Cms/FooBundle/SensioCmsFooBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Sensio/Cms/FooBundle/SensioCmsFooBundle.php @@ -31,8 +31,8 @@ class SensioCmsFooBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Sensio/FooBundle/SensioFooBundle.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Sensio/FooBundle/SensioFooBundle.php index 8bff870ca8..6af95fc1e9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Sensio/FooBundle/SensioFooBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Sensio/FooBundle/SensioFooBundle.php @@ -31,8 +31,8 @@ class SensioFooBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/SecurityBundle/SecurityBundle.php b/src/Symfony/Bundle/SecurityBundle/SecurityBundle.php index 20fb668113..38b6b60eb5 100644 --- a/src/Symfony/Bundle/SecurityBundle/SecurityBundle.php +++ b/src/Symfony/Bundle/SecurityBundle/SecurityBundle.php @@ -42,8 +42,8 @@ class SecurityBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/SwiftmailerBundle/SwiftmailerBundle.php b/src/Symfony/Bundle/SwiftmailerBundle/SwiftmailerBundle.php index 21d5ab6477..b472eab8ad 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/SwiftmailerBundle.php +++ b/src/Symfony/Bundle/SwiftmailerBundle/SwiftmailerBundle.php @@ -31,8 +31,8 @@ class SwiftmailerBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/TwigBundle/TwigBundle.php b/src/Symfony/Bundle/TwigBundle/TwigBundle.php index 2b9d9adb4a..681512ee5f 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigBundle.php +++ b/src/Symfony/Bundle/TwigBundle/TwigBundle.php @@ -40,8 +40,8 @@ class TwigBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/WebProfilerBundle.php b/src/Symfony/Bundle/WebProfilerBundle/WebProfilerBundle.php index b36a747f44..f72e97a2e6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/WebProfilerBundle.php +++ b/src/Symfony/Bundle/WebProfilerBundle/WebProfilerBundle.php @@ -31,8 +31,8 @@ class WebProfilerBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Bundle/ZendBundle/ZendBundle.php b/src/Symfony/Bundle/ZendBundle/ZendBundle.php index b4ae1d80fc..01b3dbd745 100644 --- a/src/Symfony/Bundle/ZendBundle/ZendBundle.php +++ b/src/Symfony/Bundle/ZendBundle/ZendBundle.php @@ -40,8 +40,8 @@ class ZendBundle extends Bundle /** * {@inheritdoc} */ - public function getPath() + protected function getPath() { - return strtr(__DIR__, '\\', '/'); + return __DIR__; } } diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index 92dc315b39..3e0a762cc4 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php @@ -27,23 +27,21 @@ abstract class Bundle extends ContainerAware implements BundleInterface protected $name; /** - * Boots the Bundle. + * {@inheritDoc} */ public function boot() { } /** - * Shutdowns the Bundle. + * {@inheritDoc} */ public function shutdown() { } /** - * Returns the bundle parent name. - * - * @return string The Bundle parent name it overrides or null if no parent + * {@inheritDoc} */ public function getParent() { @@ -51,9 +49,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface } /** - * Returns the bundle name (the class short name). - * - * @return string The Bundle name + * {@inheritDoc} */ final public function getName() { @@ -67,6 +63,14 @@ abstract class Bundle extends ContainerAware implements BundleInterface return $this->name = false === $pos ? $name : substr($name, $pos + 1); } + /** + * {@inheritDoc} + */ + final public function getNormalizedPath() + { + return strtr($this->getPath(), '\\', '/'); + } + /** * Finds and registers Dependency Injection Container extensions. * @@ -79,7 +83,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface */ public function registerExtensions(ContainerBuilder $container) { - if (!$dir = realpath($this->getPath().'/DependencyInjection')) { + if (!$dir = realpath($this->getNormalizedPath().'/DependencyInjection')) { return; } @@ -106,7 +110,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface */ public function registerCommands(Application $application) { - if (!$dir = realpath($this->getPath().'/Command')) { + if (!$dir = realpath($this->getNormalizedPath().'/Command')) { return; } @@ -121,4 +125,11 @@ abstract class Bundle extends ContainerAware implements BundleInterface } } } + + /** + * Gets the Bundle directory path. + * + * @return string The Bundle absolute path + */ + abstract protected function getPath(); } diff --git a/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php b/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php index 1e4f2a7487..9619c01e28 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php +++ b/src/Symfony/Component/HttpKernel/Bundle/BundleInterface.php @@ -29,9 +29,9 @@ interface BundleInterface function shutdown(); /** - * Returns the bundle parent class. + * Returns the bundle parent name. * - * @return string The Bundle parent class name it overrides or null if no parent + * @return string The Bundle parent name it overrides or null if no parent */ function getParent(); @@ -56,5 +56,5 @@ interface BundleInterface * * @return string The Bundle absolute path */ - function getPath(); + function getNormalizedPath(); } diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index da64b790a7..c46d9bf1a1 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -237,7 +237,7 @@ abstract class Kernel implements KernelInterface } foreach ($this->getBundle($bundle, false) as $bundle) { - if (file_exists($file = $bundle->getPath().'/'.$path)) { + if (file_exists($file = $bundle->getNormalizedPath().'/'.$path)) { if ($first) { return $file; } diff --git a/src/Symfony/Component/HttpKernel/bootstrap.php b/src/Symfony/Component/HttpKernel/bootstrap.php index be9cf03a35..64e1801259 100644 --- a/src/Symfony/Component/HttpKernel/bootstrap.php +++ b/src/Symfony/Component/HttpKernel/bootstrap.php @@ -228,7 +228,7 @@ interface BundleInterface function getParent(); function getName(); function getNamespace(); - function getPath(); + function getNormalizedPath(); } } namespace Symfony\Component\HttpKernel\Bundle @@ -255,12 +255,17 @@ abstract class Bundle extends ContainerAware implements BundleInterface if (null !== $this->name) { return $this->name; } - $pos = strrpos(get_class($this), '\\'); - return $this->name = substr(get_class($this), $pos ? $pos + 1 : 0); + $name = get_class($this); + $pos = strrpos($name, '\\'); + return $this->name = false === $pos ? $name : substr($name, $pos + 1); + } + final public function getNormalizedPath() + { + return strtr($this->getPath(), '\\', '/'); } public function registerExtensions(ContainerBuilder $container) { - if (!$dir = realpath($this->getPath().'/DependencyInjection')) { + if (!$dir = realpath($this->getNormalizedPath().'/DependencyInjection')) { return; } $finder = new Finder(); @@ -273,7 +278,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface } public function registerCommands(Application $application) { - if (!$dir = realpath($this->getPath().'/Command')) { + if (!$dir = realpath($this->getNormalizedPath().'/Command')) { return; } $finder = new Finder(); @@ -286,6 +291,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface } } } + abstract protected function getPath(); } } namespace Symfony\Component\HttpKernel\Debug @@ -571,7 +577,7 @@ abstract class Kernel implements KernelInterface $files[] = $file; } foreach ($this->getBundle($bundle, false) as $bundle) { - if (file_exists($file = $bundle->getPath().'/'.$path)) { + if (file_exists($file = $bundle->getNormalizedPath().'/'.$path)) { if ($first) { return $file; } @@ -1868,7 +1874,7 @@ class UniversalClassLoader public function loadClass($class) { $class = ltrim($class, '\\'); - if (false !== ($pos = strripos($class, '\\'))) { + if (false !== ($pos = strrpos($class, '\\'))) { $namespace = substr($class, 0, $pos); foreach ($this->namespaces as $ns => $dirs) { foreach ($dirs as $dir) { diff --git a/src/Symfony/Component/HttpKernel/bootstrap_cache.php b/src/Symfony/Component/HttpKernel/bootstrap_cache.php index 2753c9bb54..cd962c2de1 100644 --- a/src/Symfony/Component/HttpKernel/bootstrap_cache.php +++ b/src/Symfony/Component/HttpKernel/bootstrap_cache.php @@ -151,7 +151,7 @@ abstract class Kernel implements KernelInterface $files[] = $file; } foreach ($this->getBundle($bundle, false) as $bundle) { - if (file_exists($file = $bundle->getPath().'/'.$path)) { + if (file_exists($file = $bundle->getNormalizedPath().'/'.$path)) { if ($first) { return $file; } @@ -401,6 +401,7 @@ class HttpCache implements HttpKernelInterface protected $kernel; protected $traces; protected $store; + protected $request; protected $esi; public function __construct(HttpKernelInterface $kernel, StoreInterface $store, Esi $esi = null, array $options = array()) { @@ -430,10 +431,15 @@ class HttpCache implements HttpKernelInterface } return implode('; ', $log); } + public function getRequest() + { + return $this->request; + } public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) { if (HttpKernelInterface::MASTER_REQUEST === $type) { $this->traces = array(); + $this->request = $request; } $path = $request->getPathInfo(); if ($qs = $request->getQueryString()) { @@ -2432,7 +2438,7 @@ class UniversalClassLoader public function loadClass($class) { $class = ltrim($class, '\\'); - if (false !== ($pos = strripos($class, '\\'))) { + if (false !== ($pos = strrpos($class, '\\'))) { $namespace = substr($class, 0, $pos); foreach ($this->namespaces as $ns => $dirs) { foreach ($dirs as $dir) { diff --git a/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php b/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php new file mode 100644 index 0000000000..b3bf6fed30 --- /dev/null +++ b/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\HttpKernel\Bundle; + +class BundleTest extends \PHPUnit_Framework_TestCase +{ + public function testGetNormalizedPathReturnsANormalizedPath() + { + $bundle = $this + ->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle') + ->setMethods(array('getPath')) + ->disableOriginalConstructor() + ->getMockForAbstractClass() + ; + + $bundle + ->expects($this->once()) + ->method('getPath') + ->will($this->returnValue('path\\to\\foo\\bar')) + ; + + $this->assertEquals('path/to/foo/bar', $bundle->getNormalizedPath()); + } +} diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index 2511387ccd..5695f5a6fd 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -255,7 +255,7 @@ class KernelTest extends \PHPUnit_Framework_TestCase { $bundle = $this ->getMockBuilder('Symfony\Tests\Component\HttpKernel\BundleForTest') - ->setMethods(array('getPath', 'getParent', 'getName')) + ->setMethods(array('getNormalizedPath', 'getParent', 'getName')) ->disableOriginalConstructor() ; @@ -273,8 +273,8 @@ class KernelTest extends \PHPUnit_Framework_TestCase $bundle ->expects($this->any()) - ->method('getPath') - ->will($this->returnValue($dir)) + ->method('getNormalizedPath') + ->will($this->returnValue(strtr($dir, '\\', '/'))) ; $bundle