Skip to content

Commit f2c8f70

Browse files
committed
Refactor config/Common.php
1 parent 91815ef commit f2c8f70

File tree

3 files changed

+13
-37
lines changed

3 files changed

+13
-37
lines changed

config/Common.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public function define(Container $di)
5454
public function modify(Container $di)
5555
{
5656
$this->modifyLogger($di);
57-
$this->modifyCliDispatcher($di);
58-
$this->modifyCliHelpService($di);
57+
$this->modifyCliDispatcherAndHelp($di);
5958
}
6059

6160
protected function modifyLogger(Container $di)
@@ -73,12 +72,13 @@ protected function modifyLogger(Container $di)
7372
));
7473
}
7574

76-
protected function modifyCliDispatcher(Container $di)
75+
protected function modifyCliDispatcherAndHelp(Container $di)
7776
{
7877
// $context = $di->get('aura/cli-kernel:context');
7978
// $stdio = $di->get('aura/cli-kernel:stdio');
8079
// $logger = $di->get('aura/project-kernel:logger');
8180
$dispatcher = $di->get('aura/cli-kernel:dispatcher');
81+
$help_service = $di->get('aura/cli-kernel:help_service');
8282

8383
// register system commands
8484
foreach ($this->commands as $command) {
@@ -88,31 +88,17 @@ protected function modifyCliDispatcher(Container $di)
8888
$command_name,
8989
$di->lazyNew($class)
9090
);
91-
}
92-
93-
// register user commands
94-
UserConfig::registerCommands($di, $dispatcher, $this->user_command_paths);
95-
}
96-
97-
protected function modifyCliHelpService(Container $di)
98-
{
99-
$help_service = $di->get('aura/cli-kernel:help_service');
10091

101-
// register system command helps
102-
foreach ($this->commands as $command) {
103-
$class = 'Kenjis\CodeIgniter_Cli\Command\\' . $command . 'Help';
104-
$command_name = strtolower($command);
92+
$help_class = 'Kenjis\CodeIgniter_Cli\Command\\' . $command . 'Help';
10593
$help_service->set(
10694
$command_name,
107-
$di->lazyNew($class)
95+
$di->lazyNew($help_class)
10896
);
10997
}
11098

111-
// register user command helps
112-
UserConfig::registerCommandHelps(
113-
$di,
114-
$help_service,
115-
$this->user_command_paths
99+
// register user commands
100+
UserConfig::registerCommands(
101+
$di, $dispatcher, $help_service, $this->user_command_paths
116102
);
117103
}
118104
}

src/UserConfig.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ protected static function findClass(Container $di, $file)
5050
return $classname;
5151
}
5252

53-
public static function registerCommands(Container $di, $dispatcher, array $paths)
53+
public static function registerCommands(
54+
Container $di, $dispatcher, $help_service, array $paths
55+
)
5456
{
5557
foreach ($paths as $path) {
5658
foreach (glob($path . '*Command.php') as $file) {
@@ -65,12 +67,7 @@ public static function registerCommands(Container $di, $dispatcher, array $paths
6567
$di->lazyNew($classname)
6668
);
6769
}
68-
}
69-
}
7070

71-
public static function registerCommandHelps(Container $di, $help_service, array $paths)
72-
{
73-
foreach ($paths as $path) {
7471
foreach (glob($path . '*CommandHelp.php') as $file) {
7572
$classname = static::findClass($di, $file);
7673
if ($classname === '') {

tests/UserConfigTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,15 @@ public function test_registerCommands()
5959
]
6060
));
6161
$dispatcher = $this->di->get('aura/cli-kernel:dispatcher');
62-
$paths = [ __DIR__ . '/Fake/user_commands/' ];
63-
UserConfig::registerCommands($this->di, $dispatcher, $paths);
64-
65-
$this->assertTrue($dispatcher->hasObject('test'));
66-
}
67-
68-
public function test_registerCommandHelps()
69-
{
7062
$this->di->set(
7163
'aura/cli-kernel:help_service',
7264
$this->di->lazyNew('Aura\Cli_Kernel\HelpService')
7365
);
7466
$help_service = $this->di->get('aura/cli-kernel:help_service');
7567
$paths = [ __DIR__ . '/Fake/user_commands/' ];
76-
UserConfig::registerCommandHelps($this->di, $help_service, $paths);
68+
UserConfig::registerCommands($this->di, $dispatcher, $help_service, $paths);
7769

70+
$this->assertTrue($dispatcher->hasObject('test'));
7871
$this->assertTrue($help_service->has('test'));
7972
}
8073
}

0 commit comments

Comments
 (0)