3
3
namespace Ipunkt \Laravel \PackageManager \Providers ;
4
4
5
5
use Illuminate \Support \ServiceProvider ;
6
+ use Illuminate \Support \Str ;
6
7
7
8
class ArtisanServiceProvider extends ServiceProvider
8
9
{
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 = [];
18
19
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 ;
25
26
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
+ }
36
37
37
- $ this ->registerCommands ($ this ->commands );
38
- }
38
+ $ this ->registerCommands ($ this ->commands );
39
+ }
39
40
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
+ }
55
54
56
- $ method = "register {$ command }" ;
55
+ foreach ($ commands as $ key => $ command ) {
56
+ if (is_numeric ($ key )) {
57
+ $ key = Str::lower (str_replace ("\\" , '. ' , $ command ));
58
+ }
57
59
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 }" ;
71
61
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
+ }
74
76
}
0 commit comments