-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Console\App\Commands; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Process\Process; | ||
use Symfony\Component\Process\Exception\ProcessFailedException; | ||
|
||
/** | ||
* Url Command class. | ||
*/ | ||
class PrintHostsEntries extends Command | ||
{ | ||
use ChirripoCommandTrait; | ||
|
||
protected $availableServices; | ||
|
||
protected function configure() | ||
{ | ||
$this->availableServices = [ | ||
'nginx', | ||
'varnish', | ||
'solr', | ||
'mailhog', | ||
]; | ||
$this->setName('hosts') | ||
->setDescription('Get hosts entries if you are using proxy'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->setupEnv(); | ||
|
||
$hosts_entry = ''; | ||
|
||
if (!empty($_ENV['VIRTUAL_HOST'])) { | ||
$hosts_entry = '127.0.0.1 '; | ||
$hosts = []; | ||
foreach ($this->availableServices as $service) { | ||
if ($service === 'nginx') { | ||
$hosts[] = $_ENV['VIRTUAL_HOST']; | ||
} else { | ||
$hosts[] = $service . '.' . $_ENV['VIRTUAL_HOST']; | ||
} | ||
} | ||
$hosts_entry .= implode(' ', $hosts); | ||
} | ||
if (!empty($_ENV['OTHER_VIRTUAL_HOSTS'])) { | ||
$hosts_entry .= ' ' . $_ENV['OTHER_VIRTUAL_HOSTS']; | ||
} | ||
|
||
if ($hosts_entry) { | ||
$output->writeln(sprintf( | ||
"Add the following line to your hosts file (/etc/hosts for Linux and Mac)\n\n%s", | ||
$hosts_entry | ||
)); | ||
} else { | ||
$output->writeln(sprintf('You need to define VIRTUAL_HOST and optionally OTHER_VIRTUAL_HOSTS | ||
to use domain names')); | ||
exit(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters