Permalink
Switch branches/tags
3.x 4.x 5.x 6.x-fulltest 6.x 7.x 8.x 9.5.x Drush-call alias-search-fix annotation-drush7 avoid-header-interaction backend-stdin batch-no-output better-bootstrap-refactor better-site-alias-docs bootstrap-state-isolation cc-bootstrap-errs chmod-settings-8 chmod-settings circleci2.1 command-cache compatible-status completion config-alias-repl coveralls dcf-composerjson docs-update drop-symfony2 drupal-core-strict drush9-services-yml dsnopek-mysqli-extension-2 editor ensure-mysql-available environment-inc-cleanup everyone-luvs-global-drush exclude-vendor find-uri-from-cwd fix-6-backport fix-6 fix-defaults fix-double-exec fix-file-alias-path fix-getmultiple fix-max fix-unish-path-repo generic-alias gh-pages guard-service-cache hook-order inflect-alias-manager integration-tests-2 interact-hook isolation-via-test-scenarios luv-4-global-drush master-fulltest master merge-config-paths moar-testability mv-during-pm-download output-filter pass-unknown-to-site-local paths-for-local-redispatch-only php-72-isolation phpunit6 preflight-sitelocator preserve-contrib-dir-backport private-yml-parser process-replacement property-list psr-4 remote-sitespecs remote-unknown-commands remove-annotation-adapter remove-command-inc remove-sitealias rename-drush-service-cache sa-multipart-aliases shippable si-for-ci-drush8 si-for-ci si-profile simplified-site-aliases site-alias-location-filters sitealias-refactor skip-shippable sql-fetch ssh-tty-option support-docs symfony-dispatch-remove-contexts symfony-dispatch-remove-some-preflight tagged-services test-bootstrap-none test-symfony-dispatch unstructured-data-fields update-no-bootstrap use-mysqli useProcess user-check-if-blocked
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (52 sloc) 2.37 KB
<?php
namespace Drush\Commands\core;
use Drupal\Core\Url;
use Drush\Commands\DrushCommands;
use Drush\Drush;
use Drush\Exec\ExecTrait;
use Consolidation\SiteAlias\SiteAliasManagerAwareInterface;
use Consolidation\SiteAlias\SiteAliasManagerAwareTrait;
class BrowseCommands extends DrushCommands implements SiteAliasManagerAwareInterface
{
use ExecTrait;
use SiteAliasManagerAwareTrait;
/**
* Display a link to a given path or open link in a browser.
*
* @command browse
*
* @param string|null $path Path to open. If omitted, the site front page will be opened.
* @param array $options An associative array of options whose values come from cli, aliases, config, etc.
* @option string $browser Specify a particular browser (defaults to operating system default). Use --no-browser to suppress opening a browser.
* @option integer $redirect-port The port that the web server is redirected to (e.g. when running within a Vagrant environment).
* @usage drush browse
* Open default web browser (if configured or detected) to the site front page.
* @usage drush browse node/1
* Open web browser to the path node/1.
* @usage drush @example.prod
* Open a browser to the web site specified in a site alias.
* @usage drush browse --browser=firefox admin
* Open Firefox web browser to the path 'admin'.
* @handle-remote-commands true
*/
public function browse($path = '', array $options = ['browser' => self::REQ, 'redirect-port' => self::REQ])
{
$aliasRecord = $this->siteAliasManager()->getSelf();
// Redispatch if called against a remote-host so a browser is started on the
// the *local* machine.
if ($aliasRecord->isRemote()) {
$process = Drush::drush($aliasRecord, 'browse', [$path], Drush::redispatchOptions());
$process->mustRun();
$link = $process->getOutput();
} else {
if (!Drush::bootstrapManager()->doBootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
// Fail gracefully if unable to bootstrap Drupal. drush_bootstrap() has
// already logged an error.
return false;
}
$link = Url::fromUserInput('/' . $path, ['absolute' => true])->toString();
}
$this->startBrowser($link, false, $options['redirect-port']);
return $link;
}
}