1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-06 00:40:06 +01:00

use getStub to allow custom stub files

This commit is contained in:
Jerry Price
2022-04-13 10:50:41 -04:00
parent 08b8ccc2ca
commit 021a4d1a5c
7 changed files with 32 additions and 17 deletions

View File

@@ -78,7 +78,7 @@ public function createDriversDirectory()
$this->files->putAsUser( $this->files->putAsUser(
$driversDirectory.'/SampleValetDriver.php', $driversDirectory.'/SampleValetDriver.php',
$this->files->get(__DIR__.'/../stubs/SampleValetDriver.php') $this->files->getStub('SampleValetDriver.php')
); );
} }

View File

@@ -100,7 +100,7 @@ public function ensureUsingDnsmasqDForConfigs()
} }
// add a valet-specific config file to point to user's home directory valet config // add a valet-specific config file to point to user's home directory valet config
$contents = $this->files->get(__DIR__.'/../stubs/etc-dnsmasq-valet.conf'); $contents = $this->files->getStub('etc-dnsmasq-valet.conf');
$contents = str_replace('VALET_HOME_PATH', VALET_HOME_PATH, $contents); $contents = str_replace('VALET_HOME_PATH', VALET_HOME_PATH, $contents);
$this->files->ensureDirExists($this->dnsmasqSystemConfDir, user()); $this->files->ensureDirExists($this->dnsmasqSystemConfDir, user());
$this->files->putAsUser($this->dnsmasqSystemConfDir.'/dnsmasq-valet.conf', $contents); $this->files->putAsUser($this->dnsmasqSystemConfDir.'/dnsmasq-valet.conf', $contents);

View File

@@ -339,4 +339,21 @@ public function scandir($path)
return in_array($file, ['.', '..']); return in_array($file, ['.', '..']);
})->values()->all(); })->values()->all();
} }
/**
* Get custom stub file if exists
*
* @param string $filename
* @return string
*/
public function getStub($filename)
{
$default = __DIR__.'/../stubs/'.$filename;
$custom = VALET_HOME_PATH.'/stubs/'.$filename;
$path = file_exists($custom) ? $custom : $default;
return $this->get($path);
}
} }

View File

@@ -58,7 +58,7 @@ public function installConfiguration()
{ {
info('Installing nginx configuration...'); info('Installing nginx configuration...');
$contents = $this->files->get(__DIR__.'/../stubs/nginx.conf'); $contents = $this->files->getStub('nginx.conf');
$this->files->putAsUser( $this->files->putAsUser(
static::NGINX_CONF, static::NGINX_CONF,
@@ -80,13 +80,13 @@ public function installServer()
str_replace( str_replace(
['VALET_HOME_PATH', 'VALET_SERVER_PATH', 'VALET_STATIC_PREFIX'], ['VALET_HOME_PATH', 'VALET_SERVER_PATH', 'VALET_STATIC_PREFIX'],
[VALET_HOME_PATH, VALET_SERVER_PATH, VALET_STATIC_PREFIX], [VALET_HOME_PATH, VALET_SERVER_PATH, VALET_STATIC_PREFIX],
$this->site->replaceLoopback($this->files->get(__DIR__.'/../stubs/valet.conf')) $this->site->replaceLoopback($this->files->getStub('valet.conf'))
) )
); );
$this->files->putAsUser( $this->files->putAsUser(
BREW_PREFIX.'/etc/nginx/fastcgi_params', BREW_PREFIX.'/etc/nginx/fastcgi_params',
$this->files->get(__DIR__.'/../stubs/fastcgi_params') $this->files->getStub('fastcgi_params')
); );
} }

View File

@@ -102,7 +102,7 @@ public function createConfigurationFiles($phpVersion)
$contents = str_replace( $contents = str_replace(
['VALET_USER', 'VALET_HOME_PATH', 'valet.sock'], ['VALET_USER', 'VALET_HOME_PATH', 'valet.sock'],
[user(), VALET_HOME_PATH, self::fpmSockName($phpVersion)], [user(), VALET_HOME_PATH, self::fpmSockName($phpVersion)],
$this->files->get(__DIR__.'/../stubs/etc-phpfpm-valet.conf') $this->files->getStub('etc-phpfpm-valet.conf')
); );
$this->files->put($fpmConfigFile, $contents); $this->files->put($fpmConfigFile, $contents);
@@ -112,13 +112,13 @@ public function createConfigurationFiles($phpVersion)
$this->files->putAsUser( $this->files->putAsUser(
$destDir.'/php-memory-limits.ini', $destDir.'/php-memory-limits.ini',
$this->files->get(__DIR__.'/../stubs/php-memory-limits.ini') $this->files->getStub('php-memory-limits.ini')
); );
$contents = str_replace( $contents = str_replace(
['VALET_USER', 'VALET_HOME_PATH'], ['VALET_USER', 'VALET_HOME_PATH'],
[user(), VALET_HOME_PATH], [user(), VALET_HOME_PATH],
$this->files->get(__DIR__.'/../stubs/etc-phpfpm-error_log.ini') $this->files->getStub('etc-phpfpm-error_log.ini')
); );
$this->files->putAsUser($destDir.'/error_log.ini', $contents); $this->files->putAsUser($destDir.'/error_log.ini', $contents);

View File

@@ -664,7 +664,7 @@ public function trustCertificate($crtPath)
*/ */
public function buildCertificateConf($path, $url) public function buildCertificateConf($path, $url)
{ {
$config = str_replace('VALET_DOMAIN', $url, $this->files->get(__DIR__.'/../stubs/openssl.conf')); $config = str_replace('VALET_DOMAIN', $url, $this->files->getStub('openssl.conf'));
$this->files->putAsUser($path, $config); $this->files->putAsUser($path, $config);
} }
@@ -679,7 +679,7 @@ public function buildSecureNginxServer($url, $siteConf = null)
{ {
if ($siteConf === null) { if ($siteConf === null) {
$siteConf = $this->replaceOldLoopbackWithNew( $siteConf = $this->replaceOldLoopbackWithNew(
$this->files->get(__DIR__.'/../stubs/secure.valet.conf'), $this->files->getStub('secure.valet.conf'),
'VALET_LOOPBACK', 'VALET_LOOPBACK',
$this->valetLoopback() $this->valetLoopback()
); );
@@ -717,7 +717,7 @@ public function isolate($valetSite, $phpVersion)
$siteConf = str_replace( $siteConf = str_replace(
['VALET_HOME_PATH', 'VALET_SERVER_PATH', 'VALET_STATIC_PREFIX', 'VALET_SITE', 'VALET_PHP_FPM_SOCKET', 'VALET_ISOLATED_PHP_VERSION'], ['VALET_HOME_PATH', 'VALET_SERVER_PATH', 'VALET_STATIC_PREFIX', 'VALET_SITE', 'VALET_PHP_FPM_SOCKET', 'VALET_ISOLATED_PHP_VERSION'],
[VALET_HOME_PATH, VALET_SERVER_PATH, VALET_STATIC_PREFIX, $valetSite, PhpFpm::fpmSockName($phpVersion), $phpVersion], [VALET_HOME_PATH, VALET_SERVER_PATH, VALET_STATIC_PREFIX, $valetSite, PhpFpm::fpmSockName($phpVersion), $phpVersion],
$this->replaceLoopback($this->files->get(__DIR__.'/../stubs/site.valet.conf')) $this->replaceLoopback($this->files->getStub('site.valet.conf'))
); );
} }
@@ -827,9 +827,7 @@ public function proxyCreate($url, $host, $secure = false)
} }
$siteConf = $this->replaceOldLoopbackWithNew( $siteConf = $this->replaceOldLoopbackWithNew(
$this->files->get( $this->files->getStub($secure ? 'secure.proxy.valet.conf' : 'proxy.valet.conf'),
$secure ? __DIR__.'/../stubs/secure.proxy.valet.conf' : __DIR__.'/../stubs/proxy.valet.conf'
),
'VALET_LOOPBACK', 'VALET_LOOPBACK',
$this->valetLoopback() $this->valetLoopback()
); );
@@ -954,7 +952,7 @@ public function updateLoopbackPlist($loopback)
str_replace( str_replace(
'VALET_LOOPBACK', 'VALET_LOOPBACK',
$loopback, $loopback,
$this->files->get(__DIR__.'/../stubs/loopback.plist') $this->files->getStub('loopback.plist')
) )
); );

View File

@@ -695,9 +695,9 @@ public function test_can_install_nginx_site_config_for_specific_php_version()
// When no Nginx file exists, it will create a new config file from the template // When no Nginx file exists, it will create a new config file from the template
$files->shouldReceive('exists')->once()->with($siteMock->nginxPath('site2.test'))->andReturn(false); $files->shouldReceive('exists')->once()->with($siteMock->nginxPath('site2.test'))->andReturn(false);
$files->shouldReceive('get') $files->shouldReceive('getStub')
->once() ->once()
->with(dirname(__DIR__).'/cli/Valet/../stubs/site.valet.conf') ->with('site.valet.conf')
->andReturn(file_get_contents(__DIR__.'/../cli/stubs/site.valet.conf')); ->andReturn(file_get_contents(__DIR__.'/../cli/stubs/site.valet.conf'));
$files->shouldReceive('putAsUser') $files->shouldReceive('putAsUser')