Quellcode durchsuchen

fixed inconsistencies in file locator classes

Fabien Potencier vor 14 Jahren
Ursprung
Commit
9cc340a262

+ 3 - 8
src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml

@@ -8,7 +8,6 @@
         <parameter key="router.class">Symfony\Component\Routing\Router</parameter>
         <parameter key="router.cached.class">Symfony\Bundle\FrameworkBundle\Routing\CachedRouter</parameter>
         <parameter key="routing.loader.class">Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader</parameter>
-        <parameter key="routing.file_locator.class">Symfony\Component\HttpKernel\Config\FileLocator</parameter>
         <parameter key="routing.resolver.class">Symfony\Component\Config\Loader\LoaderResolver</parameter>
         <parameter key="routing.loader.xml.class">Symfony\Component\Routing\Loader\XmlFileLoader</parameter>
         <parameter key="routing.loader.yml.class">Symfony\Component\Routing\Loader\YamlFileLoader</parameter>
@@ -28,23 +27,19 @@
     <services>
         <service id="routing.resolver" class="%routing.resolver.class%" public="false" />
 
-        <service id="routing.file_locator" class="%routing.file_locator.class%" public="false">
-            <argument type="service" id="kernel" />
-        </service>
-
         <service id="routing.loader.xml" class="%routing.loader.xml.class%" public="false">
             <tag name="routing.loader" />
-            <argument type="service" id="routing.file_locator" />
+            <argument type="service" id="file_locator" />
         </service>
 
         <service id="routing.loader.yml" class="%routing.loader.yml.class%" public="false">
             <tag name="routing.loader" />
-            <argument type="service" id="routing.file_locator" />
+            <argument type="service" id="file_locator" />
         </service>
 
         <service id="routing.loader.php" class="%routing.loader.php.class%" public="false">
             <tag name="routing.loader" />
-            <argument type="service" id="routing.file_locator" />
+            <argument type="service" id="file_locator" />
         </service>
 
         <service id="routing.loader.real" class="%routing.loader.class%">

+ 1 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

@@ -55,6 +55,7 @@
 
         <service id="file_locator" class="%file_locator.class%">
             <argument type="service" id="kernel" />
+            <argument>%kernel.root_dir%/Resources</argument>
         </service>
     </services>
     <interfaces>

+ 0 - 2
src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml

@@ -27,13 +27,11 @@
 
         <service id="templating.locator.uncached" class="%templating.locator.class%" public="false">
             <argument type="service" id="file_locator" />
-            <argument>%kernel.root_dir%/Resources</argument>
         </service>
 
         <service id="templating.locator.cached" class="%templating.locator.cached.class%" public="false">
             <argument>%kernel.cache_dir%</argument>
             <argument type="service" id="file_locator" />
-            <argument>%kernel.root_dir%/Resources</argument>
         </service>
 
         <service id="templating.cache_warmer.template_paths" class="%templating.cache_warmer.template_paths.class%" public="false">

+ 3 - 2
src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php

@@ -30,14 +30,15 @@ class CachedTemplateLocator extends TemplateLocator
      * @param FileLocatorInterface $locator  A FileLocatorInterface instance
      * @param string               $path     A global fallback path
      */
-    public function __construct($cacheDir, FileLocatorInterface $locator, $path)
+    public function __construct($cacheDir, FileLocatorInterface $locator)
     {
         if (!file_exists($cache = $cacheDir.'/templates.php')) {
             throw new \RuntimeException(sprintf('The template locator cache is not warmed up (%s).', $cache));
         }
 
         $this->templates = require $cache;
-        parent::__construct($locator, $path);
+
+        parent::__construct($locator);
     }
 
     /**

+ 2 - 4
src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php

@@ -29,12 +29,10 @@ class TemplateLocator implements FileLocatorInterface
      * Constructor.
      *
      * @param FileLocatorInterface $locator A FileLocatorInterface instance
-     * @param string               $path    A global fallback path
      */
-    public function __construct(FileLocatorInterface $locator, $path)
+    public function __construct(FileLocatorInterface $locator)
     {
         $this->locator = $locator;
-        $this->path = $path;
         $this->cache = array();
     }
 
@@ -63,7 +61,7 @@ class TemplateLocator implements FileLocatorInterface
         }
 
         try {
-            return $this->cache[$key] = $this->locator->locate($template->getPath(), $this->path);
+            return $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath);
         } catch (\InvalidArgumentException $e) {
             throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template, $this->path), 0, $e);
         }

+ 4 - 4
src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php

@@ -26,11 +26,11 @@ class TemplateLocatorTest extends TestCase
         $fileLocator
             ->expects($this->once())
             ->method('locate')
-            ->with($template->getPath(), '/path/to/fallback')
+            ->with($template->getPath())
             ->will($this->returnValue('/path/to/template'))
         ;
 
-        $locator = new TemplateLocator($fileLocator, '/path/to/fallback');
+        $locator = new TemplateLocator($fileLocator);
 
         $this->assertEquals('/path/to/template', $locator->locate($template));
     }
@@ -50,7 +50,7 @@ class TemplateLocatorTest extends TestCase
             ->will($this->throwException(new \InvalidArgumentException()))
         ;
 
-        $locator = new TemplateLocator($fileLocator, '/path/to/fallback');
+        $locator = new TemplateLocator($fileLocator);
 
         $locator->locate($template);
     }
@@ -60,7 +60,7 @@ class TemplateLocatorTest extends TestCase
      */
     public function testThrowsAnExceptionWhenTemplateIsNotATemplateReferenceInterface()
     {
-        $locator = new TemplateLocator($this->getFileLocator(), '/path/to/fallback');
+        $locator = new TemplateLocator($this->getFileLocator());
         $locator->locate('template');
     }
 

+ 7 - 3
src/Symfony/Component/HttpKernel/Config/FileLocator.php

@@ -22,16 +22,20 @@ use Symfony\Component\HttpKernel\KernelInterface;
 class FileLocator extends BaseFileLocator
 {
     private $kernel;
+    private $path;
 
     /**
      * Constructor.
      *
      * @param KernelInterface $kernel A KernelInterface instance
-     * @param string|array    $paths  A path or an array of paths where to look for resources
+     * @param string          $path   The path the global resource directory
+     * @param string|array $paths A path or an array of paths where to look for resources
      */
-    public function __construct(KernelInterface $kernel, array $paths = array())
+    public function __construct(KernelInterface $kernel, $path = null, array $paths = array())
     {
         $this->kernel = $kernel;
+        $this->path = $path;
+        $paths[] = $path;
 
         parent::__construct($paths);
     }
@@ -42,7 +46,7 @@ class FileLocator extends BaseFileLocator
     public function locate($file, $currentPath = null, $first = true)
     {
         if ('@' === $file[0]) {
-            return $this->kernel->locateResource($file, $currentPath, $first);
+            return $this->kernel->locateResource($file, $this->path, $first);
         }
 
         return parent::locate($file, $currentPath, $first);