\n"; exit(1); } $basePath = realpath($basePathArg) . DIRECTORY_SEPARATOR; $functionPatterns = [ '/(__)\(\s*(([\'"]).+?\3)\s*\)/', '/(_x)\(\s*([\'"].+?[\'"],\s*[\'"].+?[\'"])\s*\)/', '/(_n)\(\s*([\'"].+?[\'"],\s*[\'"].+?[\'"],\s*.+?)\s*\)/', ]; function escape(string $string): string { return str_replace('"', '\\"', $string); } function getContext(string $function, array $args): ?string { return $function === '_x' ? ($args[1] ?? null) : null; } function getDomain(string $function, array $args): ?string { if ($function === '__') { return $args[1] ?? null; } elseif ($function === '_x') { return $args[2] ?? null; } elseif ($function === '_n') { return $args[3] ?? null; } return null; } function processFile(string $path): void { global $basePath; global $functionPatterns; $code = file_get_contents($path); $relPath = substr(realpath($path), strlen($basePath)); $matches = []; foreach ($functionPatterns as $pattern) { preg_match_all($pattern, $code, $functionMatches, PREG_OFFSET_CAPTURE); for ($i = 0; $i < count($functionMatches[1]); $i += 1) { $matches[] = [ 'call' => $functionMatches[0][$i][0], 'call_offset' => $functionMatches[0][$i][1], 'name' => $functionMatches[1][$i][0], 'arguments' => $functionMatches[2][$i][0], ]; } } foreach ($matches as $match) { [$textBeforeMatch] = str_split($code, $match['call_offset']); $numberOfNewlines = strlen($textBeforeMatch) - strlen(str_replace("\n", "", $textBeforeMatch)); $lineNumber = $numberOfNewlines + 1; $argumentsPattern = "/(?s)(?getExtension()), ['html', 'hbs'], true)) { processFile($file->getRealPath()); } }