2 namespace Drush\Commands\core;
5 use Drush\Commands\DrushCommands;
7 use Drush\Exec\ExecTrait;
8 use Drush\SiteAlias\SiteAliasManagerAwareInterface;
9 use Drush\SiteAlias\SiteAliasManagerAwareTrait;
11 class BrowseCommands extends DrushCommands implements SiteAliasManagerAwareInterface
14 use SiteAliasManagerAwareTrait;
17 * Display a link to a given path or open link in a browser.
21 * @param string|null $path Path to open. If omitted, the site front page will be opened.
22 * @param array $options An associative array of options whose values come from cli, aliases, config, etc.
23 * @option string $browser Specify a particular browser (defaults to operating system default). Use --no-browser to suppress opening a browser.
24 * @option integer $redirect-port The port that the web server is redirected to (e.g. when running within a Vagrant environment).
26 * Open default web browser (if configured or detected) to the site front page.
27 * @usage drush browse node/1
28 * Open web browser to the path node/1.
29 * @usage drush @example.prod
30 * Open a browser to the web site specified in a site alias.
31 * @usage drush browse --browser=firefox admin
32 * Open Firefox web browser to the path 'admin'.
33 * @handle-remote-commands true
35 public function browse($path = '', array $options = ['browser' => self::REQ, 'redirect-port' => self::REQ])
37 $aliasRecord = $this->siteAliasManager()->getSelf();
38 // Redispatch if called against a remote-host so a browser is started on the
39 // the *local* machine.
40 if ($aliasRecord->isRemote()) {
41 $return = drush_invoke_process($aliasRecord, 'browse', [$path], Drush::redispatchOptions(), ['integrate' => true]);
42 if ($return['error_status']) {
43 throw new \Exception('Unable to execute browse command on remote alias.');
45 $link = $return['object'];
48 if (!Drush::bootstrapManager()->doBootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
49 // Fail gracefully if unable to bootstrap Drupal. drush_bootstrap() has
50 // already logged an error.
53 $link = Url::fromUserInput('/' . $path, ['absolute' => true])->toString();
56 $this->startBrowser($link, false, $options['redirect-port']);