X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fconsolidation%2Frobo%2Fsrc%2FTask%2FDevelopment%2FOpenBrowser.php;fp=vendor%2Fconsolidation%2Frobo%2Fsrc%2FTask%2FDevelopment%2FOpenBrowser.php;h=ea01b326d846604d1c2715f282e57e9dcdafd3f6;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/consolidation/robo/src/Task/Development/OpenBrowser.php b/vendor/consolidation/robo/src/Task/Development/OpenBrowser.php new file mode 100644 index 000000000..ea01b326d --- /dev/null +++ b/vendor/consolidation/robo/src/Task/Development/OpenBrowser.php @@ -0,0 +1,80 @@ +taskOpenBrowser('http://localhost') + * ->run(); + * + * // open two browser windows + * $this->taskOpenBrowser([ + * 'http://localhost/mysite', + * 'http://localhost/mysite2' + * ]) + * ->run(); + * ``` + */ +class OpenBrowser extends BaseTask +{ + /** + * @var string[] + */ + protected $urls = []; + + /** + * @param string|array $url + */ + public function __construct($url) + { + $this->urls = (array) $url; + } + + /** + * {@inheritdoc} + */ + public function run() + { + $openCommand = $this->getOpenCommand(); + + if (empty($openCommand)) { + return Result::error($this, 'no suitable browser opening command found'); + } + + foreach ($this->urls as $url) { + passthru(sprintf($openCommand, ProcessUtils::escapeArgument($url))); + $this->printTaskInfo('Opened {url}', ['url' => $url]); + } + + return Result::success($this); + } + + /** + * @return null|string + */ + private function getOpenCommand() + { + if (defined('PHP_WINDOWS_VERSION_MAJOR')) { + return 'start "web" explorer "%s"'; + } + + passthru('which xdg-open', $linux); + passthru('which open', $osx); + + if (0 === $linux) { + return 'xdg-open %s'; + } + + if (0 === $osx) { + return 'open %s'; + } + } +}