Browse Source

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
Fabien Potencier 14 years ago
parent
commit
aa3ec504ae

+ 2 - 0
UPDATE.md

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

+ 0 - 1
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

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

+ 0 - 4
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

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

+ 0 - 4
src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

@@ -56,10 +56,6 @@ class FrameworkBundle extends Bundle
             $this->container->get('error_handler');
             $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')) {
         if (file_exists($this->container->getParameter('kernel.cache_dir').'/autoload.php')) {
             $classloader = new MapFileClassLoader($this->container->getParameter('kernel.cache_dir').'/autoload.php');
             $classloader = new MapFileClassLoader($this->container->getParameter('kernel.cache_dir').'/autoload.php');
             $classloader->register(true);
             $classloader->register(true);

+ 0 - 51
src/Symfony/Component/HttpFoundation/File/File.php

@@ -440,13 +440,6 @@ class File
         'x-world/x-vrml' => 'wrl',
         '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.
      * The absolute path to the file without dots.
      *
      *
@@ -454,30 +447,6 @@ class File
      */
      */
     protected $path;
     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.
      * Constructs a new file from the given path.
      *
      *
@@ -566,26 +535,6 @@ class File
         return $this->path;
         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.
      * Returns the mime type of the file.
      *
      *

+ 0 - 22
tests/Symfony/Tests/Component/HttpFoundation/File/FileTest.php

@@ -33,28 +33,6 @@ class FileTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals(__DIR__.'/Fixtures/test.gif', (string) $this->file);
         $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()
     public function testGetNameReturnsNameWithExtension()
     {
     {
         $this->assertEquals('test.gif', $this->file->getName());
         $this->assertEquals('test.gif', $this->file->getName());