File tree Expand file tree Collapse file tree 2 files changed +29
-26
lines changed Expand file tree Collapse file tree 2 files changed +29
-26
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ public function __construct()
6161 public static function call (string $ input ): int
6262 {
6363 // Tokenize input and drop placeholder tokens like [name]
64- $ tokens = self ::tokenize ($ input );
64+ $ tokens = self ::tokenizeCommand ($ input );
6565 $ tokens = array_values (array_filter ($ tokens , static function ($ t ) {
6666 return !preg_match ('/^\[[^\]]+\]$/ ' , (string )$ t );
6767 }));
@@ -75,6 +75,34 @@ public static function call(string $input): int
7575 return $ artisan ->run ($ argv );
7676 }
7777
78+ /**
79+ * Split a command string into tokens while respecting quotes.
80+ */
81+ private static function tokenizeCommand (string $ input ): array
82+ {
83+ $ input = trim ($ input );
84+ if ($ input === '' ) {
85+ return [];
86+ }
87+
88+ $ tokens = [];
89+ // Match: "double-quoted" | 'single-quoted' | unquoted\-chunks
90+ $ pattern = '/"([^" \\\\]*(?: \\\\.[^" \\\\]*)*)"| \'([^ \'\\\\]*(?: \\\\.[^ \'\\\\]*)*) \'|( \\S+)/ ' ;
91+ if (preg_match_all ($ pattern , $ input , $ matches , PREG_SET_ORDER )) {
92+ foreach ($ matches as $ m ) {
93+ if (($ m [1 ] ?? '' ) !== '' ) {
94+ $ tokens [] = stripcslashes ($ m [1 ]);
95+ } elseif (($ m [2 ] ?? '' ) !== '' ) {
96+ $ tokens [] = stripcslashes ($ m [2 ]);
97+ } else {
98+ $ tokens [] = $ m [3 ];
99+ }
100+ }
101+ }
102+
103+ return $ tokens ;
104+ }
105+
78106 /**
79107 * Register a command by name with description
80108 *
Original file line number Diff line number Diff line change @@ -28,32 +28,7 @@ trait ArtisanDiscovery
2828 private static array $ registeredProviders = [];
2929
3030
31- /**
32- * Split a command string into tokens while respecting quotes.
33- */
34- private static function tokenize (string $ input ): array
35- {
36- $ input = trim ($ input );
37- if ($ input === '' ) {
38- return [];
39- }
4031
41- $ tokens = [];
42- $ pattern = '/"([^" \\]*(?: \\.[^" \\]*)*)"| \'([^ \'\\]*(?: \\.[^ \'\\]*)*) \'|(\S+)/ ' ;
43- if (preg_match_all ($ pattern , $ input , $ matches , PREG_SET_ORDER )) {
44- foreach ($ matches as $ m ) {
45- if (($ m [1 ] ?? '' ) !== '' ) {
46- $ tokens [] = stripcslashes ($ m [1 ]);
47- } elseif (($ m [2 ] ?? '' ) !== '' ) {
48- $ tokens [] = stripcslashes ($ m [2 ]);
49- } else {
50- $ tokens [] = $ m [3 ];
51- }
52- }
53- }
54-
55- return $ tokens ;
56- }
5732
5833 /**
5934 * Discover providers by scanning vendor composer.json
You can’t perform that action at this time.
0 commit comments