authserver/homestead/src/SshCommand.php
changeset 8 5a0cbbe0922a
equal deleted inserted replaced
7:1a3fa80225b2 8:5a0cbbe0922a
       
     1 <?php namespace Laravel\Homestead;
       
     2 
       
     3 use Symfony\Component\Process\Process;
       
     4 use Symfony\Component\Console\Command\Command;
       
     5 use Symfony\Component\Console\Input\InputInterface;
       
     6 use Symfony\Component\Console\Output\OutputInterface;
       
     7 
       
     8 class SshCommand extends Command {
       
     9 
       
    10 	/**
       
    11 	 * Configure the command options.
       
    12 	 *
       
    13 	 * @return void
       
    14 	 */
       
    15 	protected function configure()
       
    16 	{
       
    17 		$this->setName('ssh')
       
    18                   ->setDescription('Login to the Homestead machine via SSH');
       
    19 	}
       
    20 
       
    21 	/**
       
    22 	 * Execute the command.
       
    23 	 *
       
    24 	 * @param  \Symfony\Component\Console\Input\InputInterface  $input
       
    25 	 * @param  \Symfony\Component\Console\Output\OutputInterface  $output
       
    26 	 * @return void
       
    27 	 */
       
    28 	public function execute(InputInterface $input, OutputInterface $output)
       
    29 	{
       
    30 		chdir(__DIR__.'/../');
       
    31 
       
    32 		passthru($this->setEnvironmentCommand() . ' vagrant ssh');
       
    33 	}
       
    34 
       
    35 	protected function setEnvironmentCommand()
       
    36 	{
       
    37 		if ($this->isWindows()) {
       
    38 			return 'SET VAGRANT_DOTFILE_PATH='.$_ENV['VAGRANT_DOTFILE_PATH'].' &&';
       
    39 		}
       
    40 
       
    41 		return 'VAGRANT_DOTFILE_PATH="'.$_ENV['VAGRANT_DOTFILE_PATH'].'"';
       
    42 	}
       
    43 
       
    44 	protected function isWindows()
       
    45 	{
       
    46 		return strpos(strtoupper(PHP_OS), 'WIN') === 0;
       
    47 	}
       
    48 
       
    49 }