コード例 #1
0
ファイル: ViewManager.php プロジェクト: vvval/spiral
 /**
  * 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;
 }
コード例 #2
0
ファイル: ViewLocator.php プロジェクト: vvval/spiral
 /**
  * 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;
 }