File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1515use function fclose ;
1616use function proc_open ;
1717use function stream_get_contents ;
18+ use const DIRECTORY_SEPARATOR ;
1819
1920/**
2021 * Class ProcFuncWrapper
@@ -223,7 +224,7 @@ public function open(): self
223224 $ options = $ this ->options ;
224225
225226 $ options ['suppress_errors ' ] = true ;
226- if ('\\' === \ DIRECTORY_SEPARATOR ) {
227+ if ('\\' === DIRECTORY_SEPARATOR ) { // windows
227228 $ options ['bypass_shell ' ] = true ;
228229 }
229230
Original file line number Diff line number Diff line change @@ -164,6 +164,35 @@ public static function getOutsideIP(): string
164164 return 'unknown ' ;
165165 }
166166
167+ /**
168+ * Open browser URL
169+ *
170+ * Mac:
171+ * open 'https://swoft.org'
172+ *
173+ * Linux:
174+ * x-www-browser 'https://swoft.org'
175+ *
176+ * Windows:
177+ * cmd /c start https://swoft.org
178+ *
179+ * @param string $pageUrl
180+ */
181+ public static function openBrowser (string $ pageUrl ): void
182+ {
183+ if (self ::isMac ()) {
184+ $ cmd = "open \"{$ pageUrl }\"" ;
185+ } elseif (self ::isWin ()) {
186+ // $cmd = 'cmd /c start';
187+ $ cmd = "start {$ pageUrl }" ;
188+ } else {
189+ $ cmd = "x-www-browser \"{$ pageUrl }\"" ;
190+ }
191+
192+ // Show::info("Will open the page on browser:\n $pageUrl");
193+ self ::execute ($ cmd );
194+ }
195+
167196 /**
168197 * get screen size
169198 *
You can’t perform that action at this time.
0 commit comments