Esempio n. 1
0
 /**
  * Detect compiler by view path (automatically resolved based on extension).
  *
  * @todo cache needed?
  * @param string $path
  * @return string
  */
 protected function detectEngine($path)
 {
     if (isset($this->associationCache[$path])) {
         return $this->associationCache[$path];
     }
     //File extension can help us to detect engine faster (attention, does not work with complex
     //extensions at this moment).
     $extension = $this->files->extension($path);
     $detected = null;
     foreach ($this->config->getEngines() as $engine) {
         if (!empty($extension) && $extension == $this->config->engineExtension($engine)) {
             //Found by extension
             $detected = $engine;
             break;
         }
         //Trying automatic (no extension) detection
         $loader = $this->loader($engine);
         try {
             if (!empty($loader->viewName($path))) {
                 $detected = $engine;
             }
         } catch (LoaderException $exception) {
             //Does not related to such engine
         }
     }
     if (empty($detected)) {
         throw new ViewsException("Unable to detect view engine for '{$path}'.");
     }
     return $this->associationCache[$path] = $detected;
 }
Esempio n. 2
0
 /**
  * @param ViewsConfig    $config
  * @param FilesInterface $files
  */
 public function perform(ViewsConfig $config, FilesInterface $files)
 {
     if (!$files->exists($config->cacheDirectory())) {
         $this->writeln("Cache directory is missing, no cache to be cleaned.");
         return;
     }
     $this->isVerbosity() && $this->writeln("<info>Clearing view cache:</info>");
     $cachedViews = $files->getFiles($config->cacheDirectory());
     foreach ($cachedViews as $filename) {
         $files->delete($filename);
         if ($this->isVerbosity()) {
             $this->writeln($files->relativePath($filename, $config->cacheDirectory()));
         }
     }
     if (empty($filename) && $this->isVerbosity()) {
         $this->writeln("No cached views were found.");
     }
     $this->writeln("<info>View cache has been cleared.</info>");
 }
Esempio n. 3
0
 /**
  * Find all available views for given namespace, view name associated with it's engine.
  *
  * @param string $namespace
  * @return array
  */
 public function namespaceViews($namespace)
 {
     $result = [];
     foreach ($this->config->namespaceDirectories($namespace) as $directory) {
         foreach ($this->config->getEngines() as $engine) {
             $extension = $this->config->engineExtension($engine);
             $finder = new Finder();
             foreach ($finder->in($directory)->name("*.{$extension}") as $file) {
                 /**
                  * @var SplFileInfo $file
                  */
                 if (isset($result[$file->getRelativePathname()])) {
                     continue;
                 }
                 $result[$file->getRelativePathname()] = $engine;
             }
         }
     }
     return $result;
 }