@@ -15,6 +15,8 @@ class Request extends Message implements RequestInterface
1515 private $ requestTarget ;
1616 protected $ headers ;
1717 protected $ body ;
18+ protected $ cliKeywords ;
19+ protected $ cliArgs ;
1820
1921 public function __construct (
2022 string $ method ,
@@ -153,4 +155,55 @@ private function resolveRequestStream(StreamInterface|array|string|null $body):
153155 }
154156 return $ stream ;
155157 }
158+
159+ /**
160+ * Get Cli keyword
161+ * @return string|null
162+ */
163+ public function getCliKeyword (): ?string
164+ {
165+ if (is_null ($ this ->cliKeywords )) {
166+ $ new = array ();
167+ $ arg = $ this ->getUri ()->getArgv ();
168+ foreach ($ arg as $ val ) {
169+ if (is_string ($ val )) {
170+ if ((strpos ($ val , "-- " ) === 0 ) || (strpos ($ val , "- " ) === 0 )) {
171+ break ;
172+ } else {
173+ $ new [] = $ val ;
174+ }
175+ }
176+ }
177+ array_shift ($ new );
178+ $ this ->cliKeywords = implode ("/ " , $ new );
179+ }
180+
181+ return $ this ->cliKeywords ;
182+ }
183+
184+ /**
185+ * Get Cli arguments
186+ * @return array
187+ */
188+ public function getCliArgs (): array
189+ {
190+ if (is_null ($ this ->cliArgs )) {
191+ $ args = $ this ->getUri ()->getArgv ();
192+ $ this ->cliArgs = array ();
193+ foreach ($ args as $ arg ) {
194+ if (is_string ($ arg )) {
195+ $ arg = str_replace ("& " , "# " , $ arg );
196+ if ((($ pos1 = strpos ($ arg , "-- " )) === 0 ) || (strpos ($ arg , "- " ) === 0 )) {
197+ parse_str (substr ($ arg , ($ pos1 !== false ? 2 : 1 )), $ result );
198+ foreach ($ result as &$ val ) {
199+ $ val = str_replace ("# " , "& " , $ val );
200+ }
201+ $ this ->cliArgs = array_merge ($ this ->cliArgs , $ result );
202+ }
203+ }
204+ }
205+ }
206+
207+ return $ this ->cliArgs ;
208+ }
156209}
0 commit comments