SymfonyComponentTranslationExtractorAbstractFileExtractor

Base class used by classes that extract translation messages from files.

Defined (1)

The class is defined in the following location(s).

/vendor/symfony/translation/Extractor/AbstractFileExtractor.php  
  1. abstract class AbstractFileExtractor 
  2. /** 
  3. * @param string|array $resource files, a file or a directory 
  4. * @return array 
  5. */ 
  6. protected function extractFiles($resource) 
  7. if (is_array($resource) || $resource instanceof \Traversable) { 
  8. $files = array(); 
  9. foreach ($resource as $file) { 
  10. if ($this->canBeExtracted($file)) { 
  11. $files[] = $this->toSplFileInfo($file); 
  12. } elseif (is_file($resource)) { 
  13. $files = $this->canBeExtracted($resource) ? array($this->toSplFileInfo($resource)) : array(); 
  14. } else { 
  15. $files = $this->extractFromDirectory($resource); 
  16.  
  17. return $files; 
  18.  
  19. /** 
  20. * @param string $file 
  21. * @return \SplFileInfo 
  22. */ 
  23. private function toSplFileInfo($file) 
  24. return ($file instanceof \SplFileInfo) ? $file : new \SplFileInfo($file); 
  25.  
  26. /** 
  27. * @param string $file 
  28. * @return bool 
  29. * @throws InvalidArgumentException 
  30. */ 
  31. protected function isFile($file) 
  32. if (!is_file($file)) { 
  33. throw new InvalidArgumentException(sprintf('The "%s" file does not exist.', $file)); 
  34.  
  35. return true; 
  36.  
  37. /** 
  38. * @param string $file 
  39. * @return bool 
  40. */ 
  41. abstract protected function canBeExtracted($file); 
  42.  
  43. /** 
  44. * @param string|array $resource files, a file or a directory 
  45. * @return array files to be extracted 
  46. */ 
  47. abstract protected function extractFromDirectory($resource);