9531774ada4c6a408d641020c9a0fc2b2b29b810
[yaffs-website] / vendor / drush / drush / src / Commands / core / BrowseCommands.php
1 <?php
2 namespace Drush\Commands\core;
3
4 use Drupal\Core\Url;
5 use Drush\Commands\DrushCommands;
6 use Drush\Drush;
7 use Drush\Exec\ExecTrait;
8 use Drush\SiteAlias\SiteAliasManagerAwareInterface;
9 use Drush\SiteAlias\SiteAliasManagerAwareTrait;
10
11 class BrowseCommands extends DrushCommands implements SiteAliasManagerAwareInterface
12 {
13     use ExecTrait;
14     use SiteAliasManagerAwareTrait;
15
16     /**
17      * Display a link to a given path or open link in a browser.
18      *
19      * @command browse
20      *
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).
25      * @usage drush browse
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
34      */
35     public function browse($path = '', array $options = ['browser' => self::REQ, 'redirect-port' => self::REQ])
36     {
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.');
44             } else {
45                 $link = $return['object'];
46             }
47         } else {
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.
51                 return false;
52             }
53             $link = Url::fromUserInput('/' . $path, ['absolute' => true])->toString();
54         }
55
56         $this->startBrowser($link, false, $options['redirect-port']);
57         return $link;
58     }
59 }