'object', 'properties' => [ 'pattern' => [ 'type' => 'string', 'description' => 'Маска, например *.php или src/**/*.php.', ], 'path' => [ 'type' => 'string', 'description' => 'Подкаталог для поиска. По умолчанию весь корень.', ], 'limit' => [ 'type' => 'integer', 'description' => 'Сколько путей вернуть, по умолчанию ' . $this->defaultLimit . ', максимум 500.', ], ], 'required' => ['pattern'], 'additionalProperties' => false, ]; } public function handle(array $args): string { $pattern = trim((string) ($args['pattern'] ?? '')); if ($pattern === '') { return 'Пустая маска.'; } $limit = (int) ($args['limit'] ?? $this->defaultLimit); $limit = max(1, min($limit, 500)); try { $start = $this->sandbox->resolve((string) ($args['path'] ?? '')); } catch (\RuntimeException $e) { return $e->getMessage(); } if (!is_dir($start)) { return 'Это не каталог: ' . (string) ($args['path'] ?? ''); } $found = []; FileWalker::walk($start, function (string $path) use (&$found, $pattern, $limit): bool { $relative = $this->sandbox->relative($path); if (!fnmatch($pattern, $relative) && !fnmatch($pattern, basename($path))) { return true; } $size = @filesize($path); $found[] = $relative . ' (' . Bytes::human($size === false ? 0 : $size) . ')'; return count($found) < $limit; }); if ($found === []) { return 'Файлы не найдены по маске "' . $pattern . '".'; } $truncated = count($found) >= $limit; return 'Найдено ' . count($found) . ($truncated ? ' (обрезано по лимиту ' . $limit . ')' : '') . ":\n" . implode("\n", $found); } /** * @param callable(string): void $onFile */ }