From d67598406288c5de9e485ed3eda86dd9c98f993f Mon Sep 17 00:00:00 2001 From: Korvin Szanto Date: Mon, 29 Jan 2018 15:29:50 -0800 Subject: [PATCH 1/4] Set files path as a static path for concrete5 driver Previously testing a concrete5 site that had tons of 404s and required file based sessions would force each request to load sequentially causing the site to load pretty slowly. This change makes it so that the driver is aware of the files directory and markes anything within as a static file. --- cli/drivers/Concrete5ValetDriver.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cli/drivers/Concrete5ValetDriver.php b/cli/drivers/Concrete5ValetDriver.php index 0b32bfe..1bc638a 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 From 021a4d1a5c37b39ab2cbf471153c119512ef5b1f Mon Sep 17 00:00:00 2001 From: Jerry Price Date: Wed, 13 Apr 2022 10:50:41 -0400 Subject: [PATCH 2/4] use getStub to allow custom stub files --- cli/Valet/Configuration.php | 2 +- cli/Valet/DnsMasq.php | 2 +- cli/Valet/Filesystem.php | 17 +++++++++++++++++ cli/Valet/Nginx.php | 6 +++--- cli/Valet/PhpFpm.php | 6 +++--- cli/Valet/Site.php | 12 +++++------- tests/SiteTest.php | 4 ++-- 7 files changed, 32 insertions(+), 17 deletions(-) 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') From c35900eacbe5c28d921c99dba280b073b75d7212 Mon Sep 17 00:00:00 2001 From: Jerry Price Date: Wed, 13 Apr 2022 11:15:54 -0400 Subject: [PATCH 3/4] styleci update --- cli/Valet/Filesystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/Valet/Filesystem.php b/cli/Valet/Filesystem.php index 266a298..cbff03e 100644 --- a/cli/Valet/Filesystem.php +++ b/cli/Valet/Filesystem.php @@ -341,7 +341,7 @@ public function scandir($path) } /** - * Get custom stub file if exists + * Get custom stub file if exists. * * @param string $filename * @return string From 12c70c033dc96ff7d13b985a815468395487855e Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 1 Dec 2022 15:55:41 +0000 Subject: [PATCH 4/4] Apply fixes from StyleCI --- cli/drivers/Concrete5ValetDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/drivers/Concrete5ValetDriver.php b/cli/drivers/Concrete5ValetDriver.php index 9ac925a..f3e3ebd 100644 --- a/cli/drivers/Concrete5ValetDriver.php +++ b/cli/drivers/Concrete5ValetDriver.php @@ -26,7 +26,7 @@ public function serves($sitePath, $siteName, $uri) public function isStaticFile($sitePath, $siteName, $uri) { if (stripos($uri, '/application/files') === 0) { - return $sitePath . $uri; + return $sitePath.$uri; } return parent::isStaticFile($sitePath, $siteName, $uri);