2 namespace Robo\Task\Development;
4 use Robo\Task\BaseTask;
5 use Robo\Common\ProcessUtils;
9 * Opens the default's user browser
10 * code inspired from openBrowser() function in https://github.com/composer/composer/blob/master/src/Composer/Command/HomeCommand.php
14 * // open one browser window
15 * $this->taskOpenBrowser('http://localhost')
18 * // open two browser windows
19 * $this->taskOpenBrowser([
20 * 'http://localhost/mysite',
21 * 'http://localhost/mysite2'
26 class OpenBrowser extends BaseTask
34 * @param string|array $url
36 public function __construct($url)
38 $this->urls = (array) $url;
46 $openCommand = $this->getOpenCommand();
48 if (empty($openCommand)) {
49 return Result::error($this, 'no suitable browser opening command found');
52 foreach ($this->urls as $url) {
53 passthru(sprintf($openCommand, ProcessUtils::escapeArgument($url)));
54 $this->printTaskInfo('Opened {url}', ['url' => $url]);
57 return Result::success($this);
63 private function getOpenCommand()
65 if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
66 return 'start "web" explorer "%s"';
69 passthru('which xdg-open', $linux);
70 passthru('which open', $osx);