1 | <?php |
||
17 | class Extractor extends Model |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Max parsing width in columns |
||
22 | */ |
||
23 | const MAX_COLS = 500; |
||
24 | |||
25 | /** |
||
26 | * Max rows to parse per file |
||
27 | */ |
||
28 | const MAX_LINES = 5000; |
||
29 | |||
30 | /** |
||
31 | * Pattern to extract strings from JS function GplCart.text() |
||
32 | */ |
||
33 | const PATTERN_JS = '/GplCart.text\s*\(\s*([\'"])(.+?)\1\s*([\),])/s'; |
||
34 | |||
35 | /** |
||
36 | * Pattern to extract strings from TWIG function {{ text() }} |
||
37 | */ |
||
38 | const PATTERN_TWIG = '/text\s*\(\s*([\'"])(.+?)\1\s*([\),])/s'; |
||
39 | |||
40 | /** |
||
41 | * Pattern to extract strings using inline @text annotation |
||
42 | */ |
||
43 | const PATTERN_PHPDOC = '/\/\*(?:\*|\s)+@text(?:\*|\s)+\*\/\s*([\'"])(.+?)\1\s*/'; |
||
44 | |||
45 | /** |
||
46 | * Pattern to extract strings from Language::text() method |
||
47 | */ |
||
48 | const PATTERN_PHP = '/->text\s*\(\s*([\'"])(.+?)\1\s*([\),])/s'; |
||
49 | |||
50 | /** |
||
51 | * Constructor |
||
52 | */ |
||
53 | public function __construct() |
||
57 | |||
58 | /** |
||
59 | * Returns an extractor by a file extension or an array of extractors keyed by extension |
||
60 | * @param null|string $extension |
||
61 | * @return array|string |
||
62 | */ |
||
63 | public function get($extension = null) |
||
82 | |||
83 | /** |
||
84 | * Returns an array of default extractors keyed by supported file extension |
||
85 | * @return array |
||
86 | */ |
||
87 | protected function getDefault() |
||
96 | |||
97 | /** |
||
98 | * Extract strings from module.json |
||
99 | * @param string $file |
||
100 | * @return array |
||
101 | */ |
||
102 | protected function extractFromFileJson($file) |
||
118 | |||
119 | /** |
||
120 | * Returns an array of extracted strings from a file |
||
121 | * @param string $file |
||
122 | * @return array |
||
123 | */ |
||
124 | public function extractFromFile($file) |
||
153 | |||
154 | /** |
||
155 | * Returns an array of extracted strings from a source string |
||
156 | * @param string $string |
||
157 | * @param string|array $regexp_patterns |
||
158 | * @return array |
||
159 | */ |
||
160 | public function extractFromString($string, $regexp_patterns) |
||
180 | |||
181 | /** |
||
182 | * Clean up an array of extracted strings or a single string |
||
183 | * @param array|string $items |
||
184 | * @return array |
||
185 | */ |
||
186 | protected function clean($items) |
||
199 | |||
200 | /** |
||
201 | * Returns an array of scanned files to extract from or counts them |
||
202 | * @param array $options |
||
203 | * @return integer|array |
||
204 | */ |
||
205 | public function scan(array $options) |
||
230 | |||
231 | /** |
||
232 | * Whether the file can be parsed |
||
233 | * @param string $file |
||
234 | * @return bool |
||
235 | */ |
||
236 | public function isSupportedFile($file) |
||
240 | |||
241 | /** |
||
242 | * Returns an array of directories to be scanned |
||
243 | * @return array |
||
244 | */ |
||
245 | public function getScannedDirectories() |
||
257 | |||
258 | /** |
||
259 | * Recursive scans files in a directory |
||
260 | * @param string $directory |
||
261 | * @param array $results |
||
262 | * @return array |
||
263 | */ |
||
264 | protected function scanRecursive($directory, &$results = array()) |
||
288 | |||
289 | } |
||
290 |