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

refactor: load config using Util::loadCommandFromConfig() #336

Merged
merged 1 commit into from
Jun 4, 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
6 changes: 1 addition & 5 deletions src/System/Integrate/Console/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use System\Console\Style\Style;
use System\Console\Traits\PrintHelpTrait;
use System\Integrate\Application;
use System\Integrate\ConfigRepository;
use System\Integrate\ValueObjects\CommandMap;
use System\Text\Str;

Expand Down Expand Up @@ -261,9 +260,6 @@ public function commandHelp(): int
*/
private function commandMaps()
{
return array_map(
static fn ($command): CommandMap => new CommandMap($command),
Application::getIntance()[ConfigRepository::class]->get('commands', [])
);
return Util::loadCommandFromConfig(Application::getIntance());
}
}
11 changes: 3 additions & 8 deletions src/System/Integrate/Console/Karnel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

namespace System\Integrate\Console;

use DI\Container;
use System\Console\Style\Style;
use System\Integrate\Application;
use System\Integrate\Bootstrap\BootProviders;
use System\Integrate\Bootstrap\ConfigProviders;
use System\Integrate\Bootstrap\RegisterProviders;
use System\Integrate\ConfigRepository;
use System\Integrate\ValueObjects\CommandMap;

class Karnel
Expand Down Expand Up @@ -168,13 +166,10 @@ public function exit_code()
/**
* Command route.
*
* @return \System\Integrate\ValueObjects\CommandMap[]
* @return CommandMap[]
*/
protected function commands()
protected function commands(): array
{
return array_map(
static fn ($command): CommandMap => new CommandMap($command),
$this->app[ConfigRepository::class]->get('commands', [])
);
return Util::loadCommandFromConfig($this->app);
}
}
29 changes: 29 additions & 0 deletions src/System/Integrate/Console/Util.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace System\Integrate\Console;

use System\Integrate\Application;
use System\Integrate\ConfigRepository;
use System\Integrate\ValueObjects\CommandMap;

final class Util
{
/**
* Convert command from array to CommandMap.
*
* @return CommandMap[]
*/
public static function loadCommandFromConfig(Application $app): array
{
$command_map = [];
foreach ($app[ConfigRepository::class]->get('commands', []) as $commands) {
foreach ($commands as $command) {
$command_map[] = new CommandMap($command);
}
}

return $command_map;
}
}
2 changes: 1 addition & 1 deletion tests/Integrate/Commands/HelpCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected function setUp(): void
{
parent::setUp();
$this->app->set('config', fn () => new ConfigRepository([
'commands' => $this->command,
'commands' => [$this->command],
]));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Integrate/Console/KarnelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function itCanCallCommand()

class NormalCommand extends Karnel
{
protected function commands()
protected function commands(): array
{
return [
// olr style
Expand Down
Loading