Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use symfony/finder to find Requests within Subdirectories #58

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
73 changes: 50 additions & 23 deletions src/Console/Commands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Support\Str;
use Illuminate\Console\Command;
use Symfony\Component\Finder\Finder;

class ListCommand extends Command
{
Expand Down Expand Up @@ -71,71 +72,97 @@ 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;
}

/**
* @return array<int, string>
*/
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;
}

/**
* @return array<int, string>
*/
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;
}

/**
* @return array<int, string>
*/
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;
}

/**
* @return array<int, string>
*/
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;
}

/**
* @return array<int, string>
*/
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
Expand All @@ -156,14 +183,14 @@ protected function getIntegrationOutput(string $integration): void
protected function getIntegrationAuthenticatorOutput(string $authenticator): void
{
$this->components->twoColumnDetail(
'<fg=red>Authenticator</> <fg=gray>...</> ' . Str::afterLast($authenticator, '/')
'<fg=red>Authenticator</> <fg=gray>...</> ' . $authenticator
);
}

protected function getIntegrationConnectorOutput(string $connector): void
{
$this->components->twoColumnDetail(
'<fg=blue>Connector</> <fg=gray>.......</> ' . Str::afterLast($connector, '/'),
'<fg=blue>Connector</> <fg=gray>.......</> ' . $connector,
'<fg=gray>' . $this->getIntegrationConnectorBaseUrl($connector) . '</>'
);
}
Expand All @@ -181,7 +208,7 @@ protected function getIntegrationRequestOutput(string $request): void

$this->components->twoColumnDetail(
'<fg=magenta>Request</> <fg=gray>.........</> ' .
Str::afterLast($request, '/'),
$request,
' <fg=gray>' . $this->getIntegrationRequestEndpoint($request) . '</>' .
' <fg=' . $requestMethodOutputColour . '>' .
Str::afterLast($this->getIntegrationRequestMethod($request), ':') . '</> '
Expand All @@ -192,15 +219,15 @@ protected function getIntegrationRequestOutput(string $request): void
protected function getIntegrationPluginOutput(string $plugin): void
{
$this->components->twoColumnDetail(
'<fg=cyan>Plugin</> <fg=gray>..........</> ' . Str::afterLast($plugin, '/')
'<fg=cyan>Plugin</> <fg=gray>..........</> ' . $plugin
);
}


protected function getIntegrationResponseOutput(string $response): void
{
$this->components->twoColumnDetail(
'<fg=yellow>Response</> <fg=gray>........</> ' . Str::afterLast($response, '/')
'<fg=yellow>Response</> <fg=gray>........</> ' . $response
);
}

Expand Down
Loading