Example #1
0
 /**
  * Watches the asset manager for changes.
  *
  * This method includes an infinite loop the continuously polls the asset
  * manager for changes.
  *
  * @param InputInterface  $input  The command input
  * @param OutputInterface $output The command output
  */
 private function watch(InputInterface $input, OutputInterface $output)
 {
     $cache = sys_get_temp_dir() . '/assetic_watch_' . substr(sha1($this->basePath), 0, 7);
     if ($input->getOption('force') || !file_exists($cache)) {
         $previously = array();
     } else {
         $previously = unserialize(file_get_contents($cache));
         if (!is_array($previously)) {
             $previously = array();
         }
     }
     $error = '';
     while (true) {
         try {
             foreach ($this->am->getNames() as $name) {
                 if ($this->checkAsset($name, $previously)) {
                     $this->dumpAsset($name, $output, $previously);
                 }
             }
             // reset the asset manager
             $this->am->clear();
             $this->am->load();
             \Dev::write_file($cache, serialize($previously));
             $error = '';
         } catch (\Exception $e) {
             if ($error != ($msg = $e->getMessage())) {
                 $output->writeln('<error>[error]</error> ' . $msg);
                 $error = $msg;
             }
         }
         usleep($input->getOption('period') * 1000000);
     }
 }
 private function resetAssetManager()
 {
     $this->am->clear();
     clearstatcache();
     $this->am->load();
 }