[Bundle] Make getPath() less error prone by allowing both backward and forward slashes
This commit is contained in:
parent
2a97f89897
commit
3ed47114d6
@ -31,8 +31,8 @@ class CompatAssetsBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,8 @@ class DoctrineBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ class AnnotationsBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
@ -17,8 +17,8 @@ class AnnotationsBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
@ -17,8 +17,8 @@ class XmlBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ class YamlBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ class DoctrineMigrationsBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ class DoctrineMongoDBBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ class AnnotationsBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ class XmlBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ class YamlBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,8 @@ class FrameworkBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ class FabpotFooBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ class FooBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ class SensioCmsFooBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ class SensioFooBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ class SecurityBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ class SwiftmailerBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ class TwigBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ class WebProfilerBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ class ZendBundle extends Bundle
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPath()
|
||||
protected function getPath()
|
||||
{
|
||||
return strtr(__DIR__, '\\', '/');
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* 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());
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Reference in New Issue
Block a user