浏览代码

[FrameworkBundle] simplified cache:clear and cache:warmup implementations

Fabien Potencier 14 年之前
父节点
当前提交
9cf9f674e8

+ 2 - 7
src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

@@ -43,13 +43,6 @@ EOF
         ;
     }
 
-    protected function initialize(InputInterface $input, OutputInterface $output)
-    {
-        parent::initialize($input, $output);
-
-        $this->cacheDir = $this->container->getParameter('kernel.environment').'_tmp';
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -65,6 +58,8 @@ EOF
         if ($input->getOption('no-warmup')) {
             rename($realCacheDir, $oldCacheDir);
         } else {
+            $this->setWarmupDir($this->container->getParameter('kernel.environment').'_tmp');
+
             parent::execute($input, $output);
 
             rename($realCacheDir, $oldCacheDir);

+ 13 - 13
src/Symfony/Bundle/FrameworkBundle/Command/CacheWarmupCommand.php

@@ -25,7 +25,7 @@ use Symfony\Component\Finder\Finder;
  */
 class CacheWarmupCommand extends Command
 {
-    protected $cacheDir;
+    protected $warmupDir;
     protected $kernelTmp;
 
     /**
@@ -37,7 +37,7 @@ class CacheWarmupCommand extends Command
             ->setName('cache:warmup')
             ->setDescription('Warms up an empty cache')
             ->setDefinition(array(
-                new InputOption('warmup-dir', '', InputOption::VALUE_OPTIONAL, 'Warms up the cache in the specified directory')
+                new InputOption('warmup-dir', '', InputOption::VALUE_REQUIRED, 'Warms up the cache in the specified directory')
             ))
             ->setHelp(<<<EOF
 The <info>cache:warmup</info> command warms up the cache.
@@ -48,15 +48,6 @@ EOF
         ;
     }
 
-    protected function initialize(InputInterface $input, OutputInterface $output)
-    {
-        parent::initialize($input, $output);
-
-        if ($input->hasOption('warmup-dir')) {
-            $this->cacheDir = $input->getOption('warmup-dir');
-        }
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -64,14 +55,18 @@ EOF
     {
         $output->writeln('Warming up the cache');
 
-        if (!$this->cacheDir) {
+        if ($input->getOption('warmup-dir')) {
+            $this->setWarmupDir($input->getOption('warmup-dir'));
+        }
+
+        if (!$this->warmupDir) {
             $this->warmUp($this->container);
         } else {
             $class = get_class($this->container->get('kernel'));
             $this->kernelTmp = new $class(
                 $this->container->getParameter('kernel.environment'),
                 $this->container->getParameter('kernel.debug'),
-                $this->cacheDir
+                $this->warmupDir
             );
 
             $this->container->get('filesystem')->remove($this->kernelTmp->getCacheDir());
@@ -89,4 +84,9 @@ EOF
         $warmer->enableOptionalWarmers();
         $warmer->warmUp($container->getParameter('kernel.cache_dir'));
     }
+
+    protected function setWarmupDir($dir)
+    {
+        $this->warmupDir = $dir;
+    }
 }