diff --git a/cli/Valet/Configuration.php b/cli/Valet/Configuration.php index 775c2d8..c09247f 100644 --- a/cli/Valet/Configuration.php +++ b/cli/Valet/Configuration.php @@ -78,7 +78,7 @@ public function createDriversDirectory() $this->files->putAsUser( $driversDirectory.'/SampleValetDriver.php', - $this->files->get(__DIR__.'/../stubs/SampleValetDriver.php') + $this->files->getStub('SampleValetDriver.php') ); } diff --git a/cli/Valet/DnsMasq.php b/cli/Valet/DnsMasq.php index 5492ad7..71616b6 100644 --- a/cli/Valet/DnsMasq.php +++ b/cli/Valet/DnsMasq.php @@ -100,7 +100,7 @@ public function ensureUsingDnsmasqDForConfigs() } // 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); $this->files->ensureDirExists($this->dnsmasqSystemConfDir, user()); $this->files->putAsUser($this->dnsmasqSystemConfDir.'/dnsmasq-valet.conf', $contents); diff --git a/cli/Valet/Filesystem.php b/cli/Valet/Filesystem.php index 30dddc6..266a298 100644 --- a/cli/Valet/Filesystem.php +++ b/cli/Valet/Filesystem.php @@ -339,4 +339,21 @@ public function scandir($path) return in_array($file, ['.', '..']); })->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); + } } diff --git a/cli/Valet/Nginx.php b/cli/Valet/Nginx.php index b938db2..e0cfdcc 100644 --- a/cli/Valet/Nginx.php +++ b/cli/Valet/Nginx.php @@ -58,7 +58,7 @@ public function installConfiguration() { info('Installing nginx configuration...'); - $contents = $this->files->get(__DIR__.'/../stubs/nginx.conf'); + $contents = $this->files->getStub('nginx.conf'); $this->files->putAsUser( static::NGINX_CONF, @@ -80,13 +80,13 @@ public function installServer() str_replace( ['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( BREW_PREFIX.'/etc/nginx/fastcgi_params', - $this->files->get(__DIR__.'/../stubs/fastcgi_params') + $this->files->getStub('fastcgi_params') ); } diff --git a/cli/Valet/PhpFpm.php b/cli/Valet/PhpFpm.php index 990a373..96b8fc8 100644 --- a/cli/Valet/PhpFpm.php +++ b/cli/Valet/PhpFpm.php @@ -102,7 +102,7 @@ public function createConfigurationFiles($phpVersion) $contents = str_replace( ['VALET_USER', 'VALET_HOME_PATH', 'valet.sock'], [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); @@ -112,13 +112,13 @@ public function createConfigurationFiles($phpVersion) $this->files->putAsUser( $destDir.'/php-memory-limits.ini', - $this->files->get(__DIR__.'/../stubs/php-memory-limits.ini') + $this->files->getStub('php-memory-limits.ini') ); $contents = str_replace( ['VALET_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); diff --git a/cli/Valet/Site.php b/cli/Valet/Site.php index 7922c85..6984846 100644 --- a/cli/Valet/Site.php +++ b/cli/Valet/Site.php @@ -664,7 +664,7 @@ public function trustCertificate($crtPath) */ 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); } @@ -679,7 +679,7 @@ public function buildSecureNginxServer($url, $siteConf = null) { if ($siteConf === null) { $siteConf = $this->replaceOldLoopbackWithNew( - $this->files->get(__DIR__.'/../stubs/secure.valet.conf'), + $this->files->getStub('secure.valet.conf'), 'VALET_LOOPBACK', $this->valetLoopback() ); @@ -717,7 +717,7 @@ public function isolate($valetSite, $phpVersion) $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, $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( - $this->files->get( - $secure ? __DIR__.'/../stubs/secure.proxy.valet.conf' : __DIR__.'/../stubs/proxy.valet.conf' - ), + $this->files->getStub($secure ? 'secure.proxy.valet.conf' : 'proxy.valet.conf'), 'VALET_LOOPBACK', $this->valetLoopback() ); @@ -954,7 +952,7 @@ public function updateLoopbackPlist($loopback) str_replace( 'VALET_LOOPBACK', $loopback, - $this->files->get(__DIR__.'/../stubs/loopback.plist') + $this->files->getStub('loopback.plist') ) ); diff --git a/tests/SiteTest.php b/tests/SiteTest.php index 7899b07..13be688 100644 --- a/tests/SiteTest.php +++ b/tests/SiteTest.php @@ -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 $files->shouldReceive('exists')->once()->with($siteMock->nginxPath('site2.test'))->andReturn(false); - $files->shouldReceive('get') + $files->shouldReceive('getStub') ->once() - ->with(dirname(__DIR__).'/cli/Valet/../stubs/site.valet.conf') + ->with('site.valet.conf') ->andReturn(file_get_contents(__DIR__.'/../cli/stubs/site.valet.conf')); $files->shouldReceive('putAsUser')