mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 16:40:05 +01:00
Merge pull request #241 from drbyte/tld-alias-for-domain-command
Rename `valet domain` command to `valet tld`
This commit is contained in:
@@ -111,7 +111,15 @@ function createCertificatesDirectory()
|
||||
function writeBaseConfiguration()
|
||||
{
|
||||
if (! $this->files->exists($this->path())) {
|
||||
$this->write(['domain' => 'test', 'paths' => []]);
|
||||
$this->write(['tld' => 'test', 'paths' => []]);
|
||||
}
|
||||
|
||||
/**
|
||||
* For upgrades, change config key 'domain' to 'tld'
|
||||
*/
|
||||
$config = $this->read();
|
||||
if (isset($config['domain']) && !isset($config['tld'])) {
|
||||
$this->updateKey('tld', $config['domain']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -130,9 +130,9 @@ function ($exitCode, $outputMessage) {
|
||||
*/
|
||||
function rewriteSecureNginxFiles()
|
||||
{
|
||||
$domain = $this->configuration->read()['domain'];
|
||||
$tld = $this->configuration->read()['tld'];
|
||||
|
||||
$this->site->resecureForNewDomain($domain, $domain);
|
||||
$this->site->resecureForNewTld($tld, $tld);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,7 +86,8 @@ function getCertificates($path)
|
||||
return collect($this->files->scandir($path))->filter(function ($value, $key) {
|
||||
return ends_with($value, '.crt');
|
||||
})->map(function ($cert) {
|
||||
return substr($cert, 0, strripos($cert, '.', -5));
|
||||
$certWithoutSuffix = substr($cert, 0, -4);
|
||||
return substr($certWithoutSuffix, 0, strrpos($certWithoutSuffix, '.'));
|
||||
})->flip();
|
||||
}
|
||||
|
||||
@@ -105,7 +106,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];
|
||||
});
|
||||
@@ -137,13 +138,13 @@ function pruneLinks()
|
||||
}
|
||||
|
||||
/**
|
||||
* Resecure all currently secured sites with a fresh domain.
|
||||
* Resecure all currently secured sites with a fresh tld.
|
||||
*
|
||||
* @param string $oldDomain
|
||||
* @param string $domain
|
||||
* @param string $oldTld
|
||||
* @param string $tld
|
||||
* @return void
|
||||
*/
|
||||
function resecureForNewDomain($oldDomain, $domain)
|
||||
function resecureForNewTld($oldTld, $tld)
|
||||
{
|
||||
if (! $this->files->exists($this->certificatesPath())) {
|
||||
return;
|
||||
@@ -156,7 +157,7 @@ function resecureForNewDomain($oldDomain, $domain)
|
||||
}
|
||||
|
||||
foreach ($secured as $url) {
|
||||
$this->secure(str_replace('.'.$oldDomain, '.'.$domain, $url));
|
||||
$this->secure(str_replace('.'.$oldTld, '.'.$tld, $url));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
Configuration::install();
|
||||
Nginx::install();
|
||||
PhpFpm::install();
|
||||
DnsMasq::install(Configuration::read()['domain']);
|
||||
DnsMasq::install(Configuration::read()['tld']);
|
||||
Nginx::restart();
|
||||
Valet::symlinkToUsersBin();
|
||||
|
||||
@@ -56,25 +56,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.
|
||||
@@ -129,7 +129,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);
|
||||
|
||||
@@ -144,7 +144,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);
|
||||
|
||||
@@ -187,7 +187,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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user