/** * Get the list of PHP code files where a lemma is defined * * @param string $lemma A lemma to search for or a regex to search for * @param array $folders An array of folder to search for lemma in * @param array $trans_methods An array of PHP lang functions * @param bool|false $regex Is lemma a regex ? * @param bool|false $shortOutput Output style for file paths * @param string $ext * * @return array|false */ public function findLemma($lemma, $folders, $trans_methods, $regex = false, $shortOutput = false, $ext = 'php') { $files = array(); foreach ($folders as $path) { foreach ($this->getFilesWithExtension($path, $ext) as $php_file_path => $dumb) { foreach ($this->extractTranslationFromPhpFile($php_file_path, $trans_methods) as $k => $v) { $real_value = eval("return {$k};"); $found = false; if ($regex) { try { $r = preg_match($lemma, $real_value); } catch (\Exception $e) { $this->messageBag->writeError("The argument is not a valid regular expression:" . str_replace('preg_match():', '', $e->getMessage())); return false; } if ($r === 1) { $found = true; } else { if ($r === false) { $this->messageBag->writeError("The argument is not a valid regular expression"); return false; } } // @codeCoverageIgnoreEnd } else { if (!(strpos($real_value, $lemma) === false)) { $found = true; } } if ($found === true) { if ($shortOutput === true) { $php_file_path = $this->getShortPath($php_file_path); } $files[] = $php_file_path; break; } } } } return $files; }