BrowseCommands.php

Namespace

Drush\CommandFiles\core

Classes

Namesort descending Description
BrowseCommands

File

lib/Drush/CommandFiles/core/BrowseCommands.php
View source
  1. <?php
  2. namespace Drush\CommandFiles\core;
  3. use Drush\CommandFiles\DrushCommands;
  4. class BrowseCommands extends DrushCommands {
  5. /**
  6. * Display a link to a given path or open link in a browser.
  7. *
  8. * @command browse
  9. *
  10. * @param string|null $path Path to open. If omitted, the site front page will be opened.
  11. * @option string $browser Specify a particular browser (defaults to operating system default). Use --no-browser to suppress opening a browser.
  12. * @todo conflicts with global option: @option integer $redirect-port The port that the web server is redirected to (e.g. when running within a Vagrant environment).
  13. * @usage drush browse
  14. * Open default web browser (if configured or detected) to the site front page.
  15. * @usage drush browse node/1
  16. * Open web browser to the path node/1.
  17. * @usage drush @example.prod
  18. * Open a browser to the web site specified in a site alias.
  19. * @usage drush browse --browser=firefox admin
  20. * Open Firefox web browser to the path 'admin'.
  21. * @complete \Drush\CommandFiles\core\BrowseCommands::complete
  22. * @handle-remote-commands true
  23. */
  24. public function browse($path = '', $options = ['browser' => NULL]) {
  25. // Redispatch if called against a remote-host so a browser is started on the
  26. // the *local* machine.
  27. $alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS');
  28. if (drush_sitealias_is_remote_site($alias)) {
  29. $site_record = drush_sitealias_get_record($alias);
  30. $return = drush_invoke_process($site_record, 'browse', [$path], drush_redispatch_get_options(), array('integrate' => TRUE));
  31. if ($return['error_status']) {
  32. return drush_set_error('Unable to execute browse command on remote alias.');
  33. }
  34. else {
  35. $link = $return['object'];
  36. }
  37. }
  38. else {
  39. if (!drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
  40. // Fail gracefully if unable to bootstrap Drupal. drush_bootstrap() has
  41. // already logged an error.
  42. return FALSE;
  43. }
  44. $link = drush_url($path, array('absolute' => TRUE));
  45. }
  46. drush_start_browser($link);
  47. return $link;
  48. }
  49. /*
  50. * An argument provider for shell completion.
  51. */
  52. static function complete() {
  53. return ['values' => ['admin', 'admin/content', 'admin/reports', 'admin/structure', 'admin/people', 'admin/modules', 'admin/config']];
  54. }
  55. }