refactor: убрать мёртвый API и сентинель-исключение
- удалены неиспользуемые ToolRegistry::all(), FileSandbox::root(), ChatResult::\ (вместе с параметром конструктора) - HttpRequestTool: allowPrivate больше не свойство, только параметр - FileWalker возвращает bool: колбэк возвращает false, чтобы остановить обход; из search_files и find_files убраны throw/catch '__limit__' - добавлены тесты лимита для search_files и find_files - 102 теста
This commit is contained in:
1 parent
27c0fc2477
commit
6734ca5289
9 files changed
+72
-66
No files matched your search
@@ -7,23 +7,24 @@ namespace AiSdk\Tools\Support;
|
||||
/**
|
||||
* Рекурсивный обход каталога с единым списком игнорируемых папок.
|
||||
*
|
||||
* Исключения из колбэка пробрасываются наружу — так инструменты
|
||||
* останавливают обход по достижении лимита.
|
||||
* Колбэк возвращает false, чтобы остановить обход: это нужно инструментам
|
||||
* с лимитом результатов.
|
||||
*/
|
||||
final class FileWalker
|
||||
{
|
||||
public const DEFAULT_IGNORE = ['.git', '.idea', '.vscode', 'vendor', 'node_modules', 'var'];
|
||||
|
||||
/**
|
||||
* @param callable(string): void $onFile
|
||||
* @param callable(string): bool $onFile вернуть false — остановить обход
|
||||
* @param list<string> $ignore
|
||||
* @return bool true — обошли всё; false — остановились по просьбе колбэка
|
||||
*/
|
||||
public static function walk(string $directory, callable $onFile, array $ignore = self::DEFAULT_IGNORE): void
|
||||
public static function walk(string $directory, callable $onFile, array $ignore = self::DEFAULT_IGNORE): bool
|
||||
{
|
||||
$entries = @scandir($directory);
|
||||
|
||||
if ($entries === false) {
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($entries as $name) {
|
||||
@@ -34,14 +35,18 @@ final class FileWalker
|
||||
$path = $directory . DIRECTORY_SEPARATOR . $name;
|
||||
|
||||
if (is_dir($path)) {
|
||||
self::walk($path, $onFile, $ignore);
|
||||
if (!self::walk($path, $onFile, $ignore)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_file($path)) {
|
||||
$onFile($path);
|
||||
if (is_file($path) && $onFile($path) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user