authserver/homestead/src/EditCommand.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 EditCommand extends Command {
       
     9 
       
    10 	/**
       
    11 	 * Configure the command options.
       
    12 	 *
       
    13 	 * @return void
       
    14 	 */
       
    15 	protected function configure()
       
    16 	{
       
    17 		$this->setName('edit')
       
    18                   ->setDescription('Edit the Homestead.yaml file');
       
    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 		$command = $this->executable().' '.homestead_path().'/Homestead.yaml';
       
    31 
       
    32 		$process = new Process($command, realpath(__DIR__.'/../'), array_merge($_SERVER, $_ENV), null, null);
       
    33 
       
    34 		$process->run(function($type, $line) use ($output)
       
    35 		{
       
    36 			$output->write($line);
       
    37 		});
       
    38 	}
       
    39 
       
    40 	/**
       
    41 	 * Find the correct executable to run depending on the OS.
       
    42 	 *
       
    43 	 * @return string
       
    44 	 */
       
    45 	protected function executable()
       
    46 	{
       
    47 		if (strpos(strtoupper(PHP_OS), 'WIN') === 0)
       
    48 		{
       
    49 			return 'start';
       
    50 		}
       
    51 		elseif (strpos(strtoupper(PHP_OS), 'DARWIN') === 0)
       
    52 		{
       
    53 			return 'open';
       
    54 		}
       
    55 
       
    56 		return 'xdg-open';
       
    57 	}
       
    58 
       
    59 }