removed File::getWebPath()

This has been removed for several reasons:

* the framework does not know where the document root is and should not care
* as the document root was static, it was impossible to have several document roots depending on some business rules (see next one)
* sometimes, the document root is not under the web root directory (so the logic of getWebPath() is not always correct)
* the feature was not used anywhere in the core
This commit is contained in:
Fabien Potencier 2011-04-27 06:44:52 +02:00
parent d9ac718b97
commit aa3ec504ae
6 changed files with 2 additions and 82 deletions

View File

@ -9,6 +9,8 @@ timeline closely anyway.
PR12 to beta1
-------------
* The `File::getWebPath()` method has been removed.
* The `session` configuration has been refactored:
* The `class` option has been removed (use the `session.class` parameter

View File

@ -39,7 +39,6 @@ class Configuration implements ConfigurationInterface
->children()
->scalarNode('cache_warmer')->defaultValue(!$this->debug)->end()
->scalarNode('charset')->end()
->scalarNode('document_root')->end()
->scalarNode('error_handler')->end()
->scalarNode('exception_controller')->defaultValue('Symfony\\Bundle\\FrameworkBundle\\Controller\\ExceptionController::showAction')->end()
->scalarNode('ide')->defaultNull()->end()

View File

@ -65,10 +65,6 @@ class FrameworkExtension extends Extension
$container->setParameter('kernel.charset', $config['charset']);
}
if (isset($config['document_root'])) {
$container->setParameter('document_root', $config['document_root']);
}
if (isset($config['error_handler'])) {
if (false === $config['error_handler']) {
$container->getDefinition('error_handler')->setMethodCalls(array());

View File

@ -56,10 +56,6 @@ class FrameworkBundle extends Bundle
$this->container->get('error_handler');
}
if ($this->container->hasParameter('document_root')) {
File::setDocumentRoot($this->container->getParameter('document_root'));
}
if (file_exists($this->container->getParameter('kernel.cache_dir').'/autoload.php')) {
$classloader = new MapFileClassLoader($this->container->getParameter('kernel.cache_dir').'/autoload.php');
$classloader->register(true);

View File

@ -440,13 +440,6 @@ class File
'x-world/x-vrml' => 'wrl',
);
/**
* Stores the absolute path to the document root directory.
*
* @var string
*/
static protected $documentRoot;
/**
* The absolute path to the file without dots.
*
@ -454,30 +447,6 @@ class File
*/
protected $path;
/**
* Sets the path to the document root directory.
*
* @param string $documentRoot
*/
static public function setDocumentRoot($documentRoot)
{
if (!is_dir($documentRoot)) {
throw new \LogicException($documentRoot . ' is not a directory.');
}
self::$documentRoot = realpath($documentRoot);
}
/**
* Returns the path to the document root directory.
*
* @return string
*/
static public function getDocumentRoot()
{
return self::$documentRoot;
}
/**
* Constructs a new file from the given path.
*
@ -566,26 +535,6 @@ class File
return $this->path;
}
/**
* Returns the path relative to the document root.
*
* You can set the document root using the static method setDocumentRoot().
* If the file is outside of the document root, this method returns an
* empty string.
*
* @return string The relative file path
*/
public function getWebPath()
{
$root = self::$documentRoot;
if (false === strpos($this->path, $root)) {
return '';
}
return str_replace(array($root, DIRECTORY_SEPARATOR), array('', '/'), $this->path);
}
/**
* Returns the mime type of the file.
*

View File

@ -33,28 +33,6 @@ class FileTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(__DIR__.'/Fixtures/test.gif', (string) $this->file);
}
public function testGetWebPathReturnsPathRelativeToDocumentRoot()
{
File::setDocumentRoot(__DIR__);
$this->assertEquals(__DIR__, File::getDocumentRoot());
$this->assertEquals('/Fixtures/test.gif', $this->file->getWebPath());
}
public function testGetWebPathReturnsEmptyPathIfOutsideDocumentRoot()
{
File::setDocumentRoot(__DIR__.'/Fixtures/directory');
$this->assertEquals('', $this->file->getWebPath());
}
public function testSetDocumentRootThrowsLogicExceptionWhenNotExists()
{
$this->setExpectedException('LogicException');
File::setDocumentRoot(__DIR__.'/Fixtures/not_here');
}
public function testGetNameReturnsNameWithExtension()
{
$this->assertEquals('test.gif', $this->file->getName());