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..cbff03e 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 7b35536..72ce377 100644 --- a/cli/Valet/PhpFpm.php +++ b/cli/Valet/PhpFpm.php @@ -104,7 +104,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); @@ -114,13 +114,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 275139c..cb8ba90 100644 --- a/cli/Valet/Site.php +++ b/cli/Valet/Site.php @@ -689,7 +689,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); } @@ -704,7 +704,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() ); @@ -742,7 +742,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')) ); } @@ -852,9 +852,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() ); @@ -979,7 +977,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/cli/drivers/Concrete5ValetDriver.php b/cli/drivers/Concrete5ValetDriver.php index 98ad35f..f3e3ebd 100644 --- a/cli/drivers/Concrete5ValetDriver.php +++ b/cli/drivers/Concrete5ValetDriver.php @@ -15,6 +15,23 @@ public function serves($sitePath, $siteName, $uri) return file_exists($sitePath.'/concrete/config/install/base'); } + /** + * Determine if the incoming request is for a static file. + * + * @param string $sitePath + * @param string $siteName + * @param string $uri + * @return string|false + */ + public function isStaticFile($sitePath, $siteName, $uri) + { + if (stripos($uri, '/application/files') === 0) { + return $sitePath.$uri; + } + + return parent::isStaticFile($sitePath, $siteName, $uri); + } + /** * @param string $sitePath * @param string $siteName diff --git a/tests/SiteTest.php b/tests/SiteTest.php index 06f996a..07d3354 100644 --- a/tests/SiteTest.php +++ b/tests/SiteTest.php @@ -770,9 +770,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')