Skip to content

Commit 6ecfc9d

Browse files
author
Robert Kummer
committed
fixed artisan service provider
1 parent 03738b9 commit 6ecfc9d

File tree

1 file changed

+60
-58
lines changed

1 file changed

+60
-58
lines changed

src/Providers/ArtisanServiceProvider.php

+60-58
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,74 @@
33
namespace Ipunkt\Laravel\PackageManager\Providers;
44

55
use Illuminate\Support\ServiceProvider;
6+
use Illuminate\Support\Str;
67

78
class ArtisanServiceProvider extends ServiceProvider
89
{
9-
/**
10-
* The commands to be registered.
11-
*
12-
* command[] or
13-
* key => command class or register command method
14-
*
15-
* @var array
16-
*/
17-
protected $commands = [];
10+
/**
11+
* The commands to be registered.
12+
*
13+
* command[] or
14+
* key => command class or register command method
15+
*
16+
* @var array
17+
*/
18+
protected $commands = [];
1819

19-
/**
20-
* Then you need to have the artisan commands all the time the app gets in action you have to change the value of this attribute
21-
*
22-
* @var bool
23-
*/
24-
protected $registerOnlyForConsole = true;
20+
/**
21+
* Then you need to have the artisan commands all the time the app gets in action you have to change the value of this attribute
22+
*
23+
* @var bool
24+
*/
25+
protected $registerOnlyForConsole = true;
2526

26-
/**
27-
* Register any application services.
28-
*
29-
* @return void
30-
*/
31-
public function register()
32-
{
33-
if ($this->registerOnlyForConsole && ! $this->app->runningInConsole()) {
34-
return;
35-
}
27+
/**
28+
* Register any application services.
29+
*
30+
* @return void
31+
*/
32+
public function register()
33+
{
34+
if ($this->registerOnlyForConsole && !$this->app->runningInConsole()) {
35+
return;
36+
}
3637

37-
$this->registerCommands($this->commands);
38-
}
38+
$this->registerCommands($this->commands);
39+
}
3940

40-
/**
41-
* registers an array of commands (key is shortname and value is command class
42-
* or part of the registerYYYCommand method name)
43-
*
44-
* @param array $commands
45-
*
46-
* @throws \Exception
47-
*/
48-
protected function registerCommands(array $commands)
49-
{
50-
$registeredCommands = [];
51-
foreach ($commands as $key => $command) {
52-
if (is_numeric($key)) {
53-
$key = $command;
54-
}
41+
/**
42+
* registers an array of commands (key is shortname and value is command class
43+
* or part of the registerYYYCommand method name)
44+
*
45+
* @param array $commands
46+
*
47+
* @throws \Exception
48+
*/
49+
protected function registerCommands(array $commands)
50+
{
51+
if (!$this->app->runningInConsole()) {
52+
return;
53+
}
5554

56-
$method = "register{$command}";
55+
foreach ($commands as $key => $command) {
56+
if (is_numeric($key)) {
57+
$key = Str::lower(str_replace("\\", '.', $command));
58+
}
5759

58-
try {
59-
if (method_exists($this, $method)) {
60-
call_user_func_array([$this, $method], [$key]);
61-
} else {
62-
$this->app->singleton($key, function ($app) use ($command) {
63-
return $app->make($command);
64-
});
65-
}
66-
$registeredCommands[] = $key;
67-
} catch (\Exception $e) {
68-
throw $e;
69-
}
70-
}
60+
$method = "register{$command}";
7161

72-
$this->commands($registeredCommands);
73-
}
62+
try {
63+
if (method_exists($this, $method)) {
64+
call_user_func_array([$this, $method], [$key]);
65+
} else {
66+
$this->app->singleton($key, function ($app) use ($command) {
67+
return $app->make($command);
68+
});
69+
}
70+
$this->commands($key);
71+
} catch (\Exception $e) {
72+
throw $e;
73+
}
74+
}
75+
}
7476
}

0 commit comments

Comments
 (0)