diff --git a/composer.json b/composer.json index 45de03e..9ba3b9f 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "php": "^8.1", "illuminate/console": "^10.0", "illuminate/support": "^10.0", - "saloonphp/saloon": "^3.5" + "saloonphp/saloon": "^3.5", + "symfony/finder": "^6.4" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.48", diff --git a/src/Console/Commands/ListCommand.php b/src/Console/Commands/ListCommand.php index feec856..43fa3e2 100644 --- a/src/Console/Commands/ListCommand.php +++ b/src/Console/Commands/ListCommand.php @@ -6,6 +6,7 @@ use Illuminate\Support\Str; use Illuminate\Console\Command; +use Symfony\Component\Finder\Finder; class ListCommand extends Command { @@ -71,11 +72,14 @@ public function handle(): int */ protected function getIntegrations(): array { - if (! $files = glob(config('saloon.integrations_path').'/*')) { - return []; + $finder = new Finder(); + $integrations = []; + + foreach ($finder->directories()->in(config('saloon.integrations_path'))->depth(0) as $integration) { + $integrations[] = $integration->getRealPath(); } - return $files; + return $integrations; } /** @@ -83,11 +87,14 @@ protected function getIntegrations(): array */ protected function getIntegrationConnectors(string $integration): array { - if (! $files = glob($integration . '/*Connector.php')) { - return []; + $finder = new Finder(); + $connectors = []; + + foreach ($finder->files()->in($integration)->depth(0) as $connector) { + $connectors[] = $connector->getRealPath(); } - return $files; + return $connectors; } /** @@ -95,11 +102,16 @@ protected function getIntegrationConnectors(string $integration): array */ protected function getIntegrationRequests(string $integration): array { - if (! $files = glob($integration . '/Requests/*')) { - return []; + $finder = new Finder(); + $requests = []; + + if (is_dir($integration . '/Requests')) { + foreach ($finder->files()->in($integration . '/Requests') as $request) { + $requests[] = $request->getRealPath(); + } } - return $files; + return $requests; } /** @@ -107,11 +119,16 @@ protected function getIntegrationRequests(string $integration): array */ protected function getIntegrationPlugins(string $integration): array { - if (! $files = glob($integration . '/Plugins/*')) { - return []; + $finder = new Finder(); + $plugins = []; + + if (is_dir($integration . '/Plugins')) { + foreach ($finder->files()->in($integration . '/Plugins') as $plugin) { + $plugins[] = $plugin->getRealPath(); + } } - return $files; + return $plugins; } /** @@ -119,11 +136,16 @@ protected function getIntegrationPlugins(string $integration): array */ protected function getIntegrationResponses(string $integration): array { - if (! $files = glob($integration . '/Responses/*')) { - return []; + $finder = new Finder(); + $responses = []; + + if (is_dir($integration . '/Responses')) { + foreach ($finder->files()->in($integration . '/Responses') as $response) { + $responses[] = $response->getRealPath(); + } } - return $files; + return $responses; } /** @@ -131,11 +153,16 @@ protected function getIntegrationResponses(string $integration): array */ protected function getIntegrationAuthenticators(string $integration): array { - if (! $files = glob($integration . '/Auth/*')) { - return []; + $finder = new Finder(); + $authenticators = []; + + if (is_dir($integration . '/Auth')) { + foreach ($finder->files()->in($integration . '/Auth') as $authenticator) { + $authenticators[] = $authenticator->getRealPath(); + } } - return $files; + return $authenticators; } protected function getIntegrationOutput(string $integration): void @@ -156,14 +183,14 @@ protected function getIntegrationOutput(string $integration): void protected function getIntegrationAuthenticatorOutput(string $authenticator): void { $this->components->twoColumnDetail( - 'Authenticator ... ' . Str::afterLast($authenticator, '/') + 'Authenticator ... ' . $authenticator ); } protected function getIntegrationConnectorOutput(string $connector): void { $this->components->twoColumnDetail( - 'Connector ....... ' . Str::afterLast($connector, '/'), + 'Connector ....... ' . $connector, '' . $this->getIntegrationConnectorBaseUrl($connector) . '' ); } @@ -181,7 +208,7 @@ protected function getIntegrationRequestOutput(string $request): void $this->components->twoColumnDetail( 'Request ......... ' . - Str::afterLast($request, '/'), + $request, ' ' . $this->getIntegrationRequestEndpoint($request) . '' . ' ' . Str::afterLast($this->getIntegrationRequestMethod($request), ':') . ' ' @@ -192,7 +219,7 @@ protected function getIntegrationRequestOutput(string $request): void protected function getIntegrationPluginOutput(string $plugin): void { $this->components->twoColumnDetail( - 'Plugin .......... ' . Str::afterLast($plugin, '/') + 'Plugin .......... ' . $plugin ); } @@ -200,7 +227,7 @@ protected function getIntegrationPluginOutput(string $plugin): void protected function getIntegrationResponseOutput(string $response): void { $this->components->twoColumnDetail( - 'Response ........ ' . Str::afterLast($response, '/') + 'Response ........ ' . $response ); }