Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / symfony / translation / Extractor / AbstractFileExtractor.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Translation\Extractor;
13
14 /**
15  * Base class used by classes that extract translation messages from files.
16  *
17  * @author Marcos D. Sánchez <marcosdsanchez@gmail.com>
18  */
19 abstract class AbstractFileExtractor
20 {
21     /**
22      * @param string|array $resource files, a file or a directory
23      *
24      * @return array
25      */
26     protected function extractFiles($resource)
27     {
28         if (is_array($resource) || $resource instanceof \Traversable) {
29             $files = array();
30             foreach ($resource as $file) {
31                 if ($this->canBeExtracted($file)) {
32                     $files[] = $this->toSplFileInfo($file);
33                 }
34             }
35         } elseif (is_file($resource)) {
36             $files = $this->canBeExtracted($resource) ? array($this->toSplFileInfo($resource)) : array();
37         } else {
38             $files = $this->extractFromDirectory($resource);
39         }
40
41         return $files;
42     }
43
44     /**
45      * @param string $file
46      *
47      * @return \SplFileInfo
48      */
49     private function toSplFileInfo($file)
50     {
51         return ($file instanceof \SplFileInfo) ? $file : new \SplFileInfo($file);
52     }
53
54     /**
55      * @param string $file
56      *
57      * @return bool
58      *
59      * @throws \InvalidArgumentException
60      */
61     protected function isFile($file)
62     {
63         if (!is_file($file)) {
64             throw new \InvalidArgumentException(sprintf('The "%s" file does not exist.', $file));
65         }
66
67         return true;
68     }
69
70     /**
71      * @param string $file
72      *
73      * @return bool
74      */
75     abstract protected function canBeExtracted($file);
76
77     /**
78      * @param string|array $resource files, a file or a directory
79      *
80      * @return array files to be extracted
81      */
82     abstract protected function extractFromDirectory($resource);
83 }