Created
May 21, 2020 15:38
-
-
Save Uplink03/96d4f08fd8f8215be036def4c8bc16f7 to your computer and use it in GitHub Desktop.
Laravel, Valet static file driver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* To enable serving of static files (i.e. bypass the Laravel front controller) | |
* Save this as: $HOME/.config/valet/Drivers/StaticValetDriver.php | |
*/ | |
class StaticValetDriver extends ValetDriver | |
{ | |
/** | |
* Determine if the driver serves the request. | |
* | |
* @param string $sitePath | |
* @param string $siteName | |
* @param string $uri | |
* @return bool | |
*/ | |
public function serves($sitePath, $siteName, $uri) | |
{ | |
return is_file($this->buildPath($sitePath, $uri)); | |
} | |
/** | |
* 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) | |
{ | |
$staticFilePath = $this->buildPath($sitePath, $uri); | |
return is_file($staticFilePath) | |
? $staticFilePath | |
: false | |
; | |
} | |
/** | |
* Get the fully resolved path to the application's front controller. | |
* | |
* @param string $sitePath | |
* @param string $siteName | |
* @param string $uri | |
* @return string | |
*/ | |
public function frontControllerPath($sitePath, $siteName, $uri) | |
{ | |
return $this->buildPath($sitePath, $uri); | |
} | |
private function buildPath($sitePath, $uri) | |
{ | |
return "$sitePath/public$uri"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment