diff --git a/core/lib/Core/Helpers/SystemFunctions.class.php b/core/lib/Core/Helpers/SystemFunctions.class.php index 9af05bd..77ef9f9 100644 --- a/core/lib/Core/Helpers/SystemFunctions.class.php +++ b/core/lib/Core/Helpers/SystemFunctions.class.php @@ -859,4 +859,88 @@ } return $arResult; } + + /** + * Возвращает подсвеченную PHP строку + * + * @param string $string Строка кода + * + * @return string Подсвеченная строка + */ + public static function highlightLine(string $string): string + { + $string = str_replace([' 0) { + $result[] = '
' . ($lineNum - 2) . '. ' . self::highlightLine($fileText[$line - 2]) . '
'; + } + + if ($lineNum - 1 > 0) { + $result[] = '
' . ($lineNum - 1) . '. ' . self::highlightLine($fileText[$line - 1]) . '
'; + } + + if ($lineNum > 0 && $lineNum <= count($fileText)) { + $result[] = '
' . $lineNum . '. ' . self::highlightLine($fileText[$line]) . '
'; + } + + if ($lineNum + 1 <= count($fileText)) { + $result[] = '
' . ($lineNum + 1) . '. ' . self::highlightLine($fileText[$line + 1]) . '
'; + } + + if ($lineNum + 2 <= count($fileText)) { + $result[] = '
' . ($lineNum + 2) . '. ' . self::highlightLine($fileText[$line + 2]) . '
'; + } + + $textBefore = '
'; + $textAfter = '
'; + return $textBefore . implode(PHP_EOL . PHP_EOL, $result) . $textAfter; + } + + /** + * Выполняет поиск строки текста в файле и отдает аннотацию + * + * @param string $text Текст + * @param string $file Путь к файлу + * + * @return string|null Результат поиска + */ + public static function findText(string $text, string $file): ?string + { + $fileText = file_get_contents($file); + $file = explode(PHP_EOL, $fileText); + foreach ($file as $line => $string) { + $pos = strripos($string, $text); + if ($pos !== false) { + return self::getFilePreviewByLine($fileText, $line + 1); + } + } + + return null; + } }