mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 00:40:06 +01:00
Change valet domain command to valet tld
Fixes #144 ".test" or ".dev" is really a TLD, not a "domain" in the conventional sense. Changing the command to `valet tld` more accurately reflects the purpose of the command (to set or get the configured TLD served by Valet) The use of `valet domain` is currently preserved as an alias for `valet tld`, but will be removed at a later date.
This commit is contained in:
@@ -33,27 +33,29 @@ function __construct(Brew $brew, CommandLine $cli, Filesystem $files)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function install($domain = 'test')
|
||||
function install($tld = 'test')
|
||||
{
|
||||
$this->brew->ensureInstalled('dnsmasq');
|
||||
|
||||
// For DnsMasq, we create our own custom configuration file which will be imported
|
||||
// in the main DnsMasq file. This allows Valet to make changes to our own files
|
||||
// without needing to modify the "primary" DnsMasq configuration files again.
|
||||
$this->createCustomConfigFile($domain);
|
||||
$this->createCustomConfigFile($tld);
|
||||
|
||||
$this->createDomainResolver($domain);
|
||||
$this->createTldResolver($tld);
|
||||
|
||||
$this->brew->restartService('dnsmasq');
|
||||
|
||||
info('Valet is configured to serve for TLD [.'.$tld.']');
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the custom DnsMasq configuration file to the main configuration file.
|
||||
*
|
||||
* @param string $domain
|
||||
* @param string $tld
|
||||
* @return void
|
||||
*/
|
||||
function createCustomConfigFile($domain)
|
||||
function createCustomConfigFile($tld)
|
||||
{
|
||||
$customConfigPath = $this->customConfigPath();
|
||||
|
||||
@@ -61,7 +63,7 @@ function createCustomConfigFile($domain)
|
||||
|
||||
$this->appendCustomConfigImport($customConfigPath);
|
||||
|
||||
$this->files->putAsUser($customConfigPath, 'address=/.'.$domain.'/127.0.0.1'.PHP_EOL.'listen-address=127.0.0.1'.PHP_EOL);
|
||||
$this->files->putAsUser($customConfigPath, 'address=/.'.$tld.'/127.0.0.1'.PHP_EOL.'listen-address=127.0.0.1'.PHP_EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,30 +109,30 @@ function customConfigIsBeingImported($customConfigPath)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the resolver file to point the configured domain to 127.0.0.1.
|
||||
* Create the resolver file to point the configured TLD to 127.0.0.1.
|
||||
*
|
||||
* @param string $domain
|
||||
* @param string $tld
|
||||
* @return void
|
||||
*/
|
||||
function createDomainResolver($domain)
|
||||
function createTldResolver($tld)
|
||||
{
|
||||
$this->files->ensureDirExists($this->resolverPath);
|
||||
|
||||
$this->files->put($this->resolverPath.'/'.$domain, 'nameserver 127.0.0.1'.PHP_EOL);
|
||||
$this->files->put($this->resolverPath.'/'.$tld, 'nameserver 127.0.0.1'.PHP_EOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the domain (TLD) used by DnsMasq.
|
||||
* Update the TLD/domain resolved by DnsMasq.
|
||||
*
|
||||
* @param string $oldDomain
|
||||
* @param string $newDomain
|
||||
* @param string $oldTld
|
||||
* @param string $newTld
|
||||
* @return void
|
||||
*/
|
||||
function updateDomain($oldDomain, $newDomain)
|
||||
function updateTld($oldTld, $newTld)
|
||||
{
|
||||
$this->files->unlink($this->resolverPath.'/'.$oldDomain);
|
||||
$this->files->unlink($this->resolverPath.'/'.$oldTld);
|
||||
|
||||
$this->install($newDomain);
|
||||
$this->install($newTld);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -104,7 +104,7 @@ function getLinks($path, $certs)
|
||||
return [$site => $this->files->readLink($path.'/'.$site)];
|
||||
})->map(function ($path, $site) use ($certs, $config) {
|
||||
$secured = $certs->has($site);
|
||||
$url = ($secured ? 'https': 'http').'://'.$site.'.'.$config['domain'];
|
||||
$url = ($secured ? 'https': 'http').'://'.$site.'.'.$config['tld'];
|
||||
|
||||
return [$site, $secured ? ' X': '', $url, $path];
|
||||
});
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
Configuration::install();
|
||||
Nginx::install();
|
||||
PhpFpm::install();
|
||||
DnsMasq::install(Configuration::read()['domain']);
|
||||
DnsMasq::install(Configuration::read()['tld']);
|
||||
Nginx::restart();
|
||||
Valet::symlinkToUsersBin();
|
||||
|
||||
@@ -52,25 +52,25 @@
|
||||
*/
|
||||
if (is_dir(VALET_HOME_PATH)) {
|
||||
/**
|
||||
* Get or set the domain currently being used by Valet.
|
||||
* Get or set the TLD currently being used by Valet.
|
||||
*/
|
||||
$app->command('domain [domain]', function ($domain = null) {
|
||||
if ($domain === null) {
|
||||
return info(Configuration::read()['domain']);
|
||||
$app->command('tld [tld]', function ($tld = null) {
|
||||
if ($tld === null) {
|
||||
return info('Valet is configured to serve for TLD: .'.Configuration::read()['tld']);
|
||||
}
|
||||
|
||||
DnsMasq::updateDomain(
|
||||
$oldDomain = Configuration::read()['domain'], $domain = trim($domain, '.')
|
||||
DnsMasq::updateTld(
|
||||
$oldTld = Configuration::read()['tld'], $tld = trim($tld, '.')
|
||||
);
|
||||
|
||||
Configuration::updateKey('domain', $domain);
|
||||
Configuration::updateKey('tld', $tld);
|
||||
|
||||
Site::resecureForNewDomain($oldDomain, $domain);
|
||||
Site::resecureForNewTld($oldTld, $tld);
|
||||
PhpFpm::restart();
|
||||
Nginx::restart();
|
||||
|
||||
info('Your Valet domain has been updated to ['.$domain.'].');
|
||||
})->descriptions('Get or set the domain used for Valet sites');
|
||||
info('Your Valet TLD has been updated to ['.$tld.'].');
|
||||
}, ['domain'])->descriptions('Get or set the TLD used for Valet sites. (Currently: .'.Configuration::read()['tld'].')');
|
||||
|
||||
/**
|
||||
* Add the current working directory to the paths configuration.
|
||||
@@ -125,7 +125,7 @@
|
||||
* Secure the given domain with a trusted TLS certificate.
|
||||
*/
|
||||
$app->command('secure [domain]', function ($domain = null) {
|
||||
$url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['domain'];
|
||||
$url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];
|
||||
|
||||
Site::secure($url);
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
* Stop serving the given domain over HTTPS and remove the trusted TLS certificate.
|
||||
*/
|
||||
$app->command('unsecure [domain]', function ($domain = null) {
|
||||
$url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['domain'];
|
||||
$url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];
|
||||
|
||||
Site::unsecure($url);
|
||||
|
||||
@@ -183,7 +183,7 @@
|
||||
* Open the current or given directory in the browser.
|
||||
*/
|
||||
$app->command('open [domain]', function ($domain = null) {
|
||||
$url = "http://".($domain ?: Site::host(getcwd())).'.'.Configuration::read()['domain'];
|
||||
$url = "http://".($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];
|
||||
CommandLine::runAsUser("open ".escapeshellarg($url));
|
||||
})->descriptions('Open the site for the current (or specified) directory in your browser');
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ function show_valet_404()
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $domain string Domain to filter
|
||||
*
|
||||
* @return string Filtered domain (without wildcard dns feature (xip.io/nip.io))
|
||||
* You may use wildcard DNS providers xip.io or nip.io as a tool for testing your site via an IP address.
|
||||
* To use it, first `valet link 192.168.3.3` (whatever your local IP is) inside your current project.
|
||||
* Then you can reach your project's dev site by visiting http://your-local-ip.xip.io (or nip.io).
|
||||
*/
|
||||
function valet_support_wildcard_dns($domain)
|
||||
{
|
||||
@@ -52,7 +52,7 @@ function valet_support_wildcard_dns($domain)
|
||||
$siteName = basename(
|
||||
// Filter host to support wildcard dns feature
|
||||
valet_support_wildcard_dns($_SERVER['HTTP_HOST']),
|
||||
'.'.$valetConfig['domain']
|
||||
'.'.$valetConfig['tld']
|
||||
);
|
||||
|
||||
if (strpos($siteName, 'www.') === 0) {
|
||||
|
||||
@@ -50,13 +50,13 @@ public function test_install_installs_and_places_configuration_files_in_proper_l
|
||||
}
|
||||
|
||||
|
||||
public function test_update_domain_removes_old_resolver_and_reinstalls()
|
||||
public function test_update_tld_removes_old_resolver_and_reinstalls()
|
||||
{
|
||||
$cli = Mockery::mock(CommandLine::class);
|
||||
$cli->shouldReceive('quietly')->with('rm /etc/resolver/old');
|
||||
$dnsMasq = Mockery::mock(DnsMasq::class.'[install]', [resolve(Brew::class), $cli, new Filesystem]);
|
||||
$dnsMasq->shouldReceive('install')->with('new');
|
||||
$dnsMasq->updateDomain('old', 'new');
|
||||
$dnsMasq->updateTld('old', 'new');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,13 +78,13 @@ public function test_install_nginx_directories_rewrites_secure_nginx_files()
|
||||
$files->shouldReceive('putAsUser')->with(VALET_HOME_PATH.'/Nginx/.keep', "\n")->once();
|
||||
|
||||
swap(Filesystem::class, $files);
|
||||
swap(Configuration::class, $config = Mockery::spy(Configuration::class, ['read' => ['domain' => 'test']]));
|
||||
swap(Configuration::class, $config = Mockery::spy(Configuration::class, ['read' => ['tld' => 'test']]));
|
||||
swap(Site::class, $site = Mockery::spy(Site::class));
|
||||
|
||||
$nginx = resolve(Nginx::class);
|
||||
$nginx->installNginxDirectory();
|
||||
|
||||
$site->shouldHaveReceived('resecureForNewDomain', ['test', 'test']);
|
||||
$site->shouldHaveReceived('resecureForNewTld', ['test', 'test']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user