From e3fbacb6b57f691ae41719c142c0917afb9e6e20 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Mon, 6 Feb 2023 18:13:12 +0300 Subject: [PATCH] =?UTF-8?q?[+]=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D0=BF=D0=BE=D0=B8?= =?UTF-8?q?=D1=81=D0=BA=D0=BE=D0=BC=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0?= =?UTF-8?q?=20=D0=B2=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Helpers/SystemFunctions.class.php | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) 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; + } }