6
6
use App \Services ;
7
7
use App \Shell \Environment ;
8
8
use Illuminate \Support \Arr ;
9
+ use Illuminate \Support \Facades \App ;
9
10
use Illuminate \Support \Str ;
10
11
use LaravelZero \Framework \Commands \Command ;
11
12
@@ -26,16 +27,11 @@ public function handle(Environment $environment, Services $services): void
26
27
$ this ->services = $ services ;
27
28
$ this ->initializeCommand ();
28
29
29
- $ services = $ this ->removePassthroughOptions ($ this ->argument ('serviceNames ' ));
30
+ $ services = $ this ->removeOptions ($ this ->serverArguments ());
31
+ $ passthroughOptions = $ this ->extractPassthroughOptions ($ this ->serverArguments ());
30
32
31
33
$ useDefaults = $ this ->option ('default ' );
32
34
33
- // Extract passthrough options, if provided, passed after "-- "
34
- $ passthroughOptions = [];
35
- if (in_array ('-- ' , $ _SERVER ['argv ' ])) {
36
- $ passthroughOptions = array_slice ($ _SERVER ['argv ' ], array_search ('-- ' , $ _SERVER ['argv ' ]) + 1 );
37
- }
38
-
39
35
if (filled ($ services )) {
40
36
foreach ($ services as $ service ) {
41
37
$ this ->enable ($ service , $ useDefaults , $ passthroughOptions );
@@ -53,17 +49,55 @@ public function handle(Environment $environment, Services $services): void
53
49
$ this ->enable ($ option , $ useDefaults , $ passthroughOptions );
54
50
}
55
51
52
+ public function serverArguments (): array
53
+ {
54
+ if (App::environment () === 'testing ' ) {
55
+ $ string = array_merge (['takeout ' , 'enable ' ], $ this ->argument ('serviceNames ' ));
56
+
57
+ if ($ this ->option ('default ' )) {
58
+ $ string [] = '--default ' ;
59
+ }
60
+
61
+ return $ string ;
62
+ }
63
+
64
+ return $ _SERVER ['argv ' ];
65
+ }
66
+
67
+ /**
68
+ * Extract and return any passthrough options from the parameters list
69
+ *
70
+ * @param array $arguments
71
+ * @return array
72
+ */
73
+ public function extractPassthroughOptions (array $ arguments ): array
74
+ {
75
+ if (! in_array ('-- ' , $ arguments )) {
76
+ return [];
77
+ }
78
+
79
+ return array_slice ($ arguments , array_search ('-- ' , $ arguments ) + 1 );
80
+ }
81
+
56
82
/**
57
- * Remove any passthrough options from the parameters list
83
+ * Remove any options or passthrough options from the parameters list
58
84
*
59
- * @param array $serviceNames
85
+ * @param array $arguments
60
86
* @return array
61
87
*/
62
- protected function removePassthroughOptions (array $ serviceNames ): array
88
+ public function removeOptions (array $ arguments ): array
63
89
{
64
- return collect ($ serviceNames )->reject (function ($ item ) {
65
- return str_starts_with ($ item , '-- ' );
66
- })->all ();
90
+ $ arguments = collect ($ arguments )->reject (fn ($ argument ) => str_starts_with ($ argument , '-- ' ) && strlen ($ argument ) > 2 )->toArray ();
91
+
92
+ $ start = array_search ('enable ' , $ arguments ) + 1 ;
93
+
94
+ if (in_array ('-- ' , $ arguments )) {
95
+ $ length = array_search ('-- ' , $ arguments ) - $ start - 1 ;
96
+
97
+ return array_slice ($ arguments , $ start , $ length );
98
+ }
99
+
100
+ return array_slice ($ arguments , $ start );
67
101
}
68
102
69
103
private function selectService (): ?string
0 commit comments