Przeglądaj źródła

fixed Router cache warmer

Fabien Potencier 14 lat temu
rodzic
commit
2a5d7687b7

+ 5 - 0
src/Symfony/Bundle/FrameworkBundle/CacheWarmer/RouterCacheWarmer.php

@@ -40,9 +40,14 @@ class RouterCacheWarmer implements CacheWarmerInterface
      */
     public function warmUp($cacheDir)
     {
+        $currentDir = $this->router->getOption('cache_dir');
+
         // force cache generation
+        $this->router->setOption('cache_dir', $cacheDir);
         $this->router->getMatcher();
         $this->router->getGenerator();
+
+        $this->router->setOption('cache_dir', $currentDir);
     }
 
     /**

+ 36 - 1
src/Symfony/Component/Routing/Router.php

@@ -82,10 +82,45 @@ class Router implements RouterInterface
         }
 
         if ($isInvalid) {
-            throw new \InvalidArgumentException(sprintf('The Router does not support the following options: \'%s\'.', implode('\', \'', $invalid)));
+            throw new \InvalidArgumentException(sprintf('The Router does not support the following options: "%s".', implode('\', \'', $invalid)));
         }
     }
 
+    /**
+     * Sets an option.
+     *
+     * @param string $key   The key
+     * @param mixed  $value The value
+     *
+     * @throw \InvalidArgumentException
+     */
+    public function setOption($key, $value)
+    {
+        if (!array_key_exists($key, $this->options)) {
+            throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
+        }
+
+        $this->options[$key] = $value;
+    }
+
+    /**
+     * Gets an option value.
+     *
+     * @param string $key The key
+     *
+     * @return mixed The value
+     *
+     * @throw \InvalidArgumentException
+     */
+    public function getOption($key)
+    {
+        if (!array_key_exists($key, $this->options)) {
+            throw new \InvalidArgumentException(sprintf('The Router does not support the "%s" option.', $key));
+        }
+
+        return $this->options[$key];
+    }
+
     /**
      * Gets the RouteCollection instance associated with this Router.
      *