[Server] Allow overriding the default file name pattern for Discovery (#292)
* Add optional namePatterns capability to discovery so that the default scan for `*.php` files can be overridden. * add default to namePatterns docs * add an error check if we manage to pass in an empty list of patterns * add unit tests (and a static entry to classmap for composer.json so it autoloads from a non .php file for the test) * run php-cs-fixer * change how default namePatterns are set and make sure all the annotations are correct * Fix bad whitespace Co-authored-by: Christopher Hertel <mail@christopher-hertel.de> * switch to a const default instead of nullable with a check in the function to convert null to a default * make sure we handle empty arrays * formatting fixes * Apply suggestion from @chr-hertel Co-authored-by: Christopher Hertel <mail@christopher-hertel.de> * Add changelog entry --------- Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
This commit is contained in:
parent
fb2c8c2ee4
commit
86bd845924
1 changed files with 109 additions and 37 deletions
|
|
@ -65,11 +65,12 @@ final class Discoverer implements DiscovererInterface
|
|||
/**
|
||||
* Discover MCP elements in the specified directories and return the discovery state.
|
||||
*
|
||||
* @param string $basePath the base path for resolving directories
|
||||
* @param array<string> $directories list of directories (relative to base path) to scan
|
||||
* @param array<string> $excludeDirs list of directories (relative to base path) to exclude from the scan
|
||||
* @param string $basePath the base path for resolving directories
|
||||
* @param array<string> $directories list of directories (relative to base path) to scan
|
||||
* @param array<string> $excludeDirs list of directories (relative to base path) to exclude from the scan
|
||||
* @param array<string> $namePatterns list of file name patterns for the scan. Compatible with Finder->name()
|
||||
*/
|
||||
public function discover(string $basePath, array $directories, array $excludeDirs = []): DiscoveryState
|
||||
public function discover(string $basePath, array $directories, array $excludeDirs = [], array $namePatterns = self::DEFAULT_NAME_PATERNS): DiscoveryState
|
||||
{
|
||||
$startTime = microtime(true);
|
||||
$discoveredCount = [
|
||||
|
|
@ -79,6 +80,8 @@ final class Discoverer implements DiscovererInterface
|
|||
'resourceTemplates' => 0,
|
||||
];
|
||||
|
||||
$namePatterns = !empty($namePatterns) ? $namePatterns : self::DEFAULT_NAME_PATERNS;
|
||||
|
||||
$tools = [];
|
||||
$resources = [];
|
||||
$prompts = [];
|
||||
|
|
@ -106,7 +109,7 @@ final class Discoverer implements DiscovererInterface
|
|||
$finder->files()
|
||||
->in($absolutePaths)
|
||||
->exclude($excludeDirs)
|
||||
->name('*.php');
|
||||
->name($namePatterns);
|
||||
|
||||
foreach ($finder as $file) {
|
||||
$this->processFile($file, $discoveredCount, $tools, $resources, $prompts, $resourceTemplates);
|
||||
|
|
|
|||
Loading…
Reference in a new issue