Last active
November 7, 2017 17:04
-
-
Save tedslittlerobot/c71bd0b05f17c2f960a38ba8db084cbe to your computer and use it in GitHub Desktop.
Local Wordpress Valet 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 | |
class LocalValetDriver extends WordpressValetDriver | |
{ | |
/** | |
* 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 true; | |
} | |
/** | |
* 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 (is_dir($this->fullFilePath($sitePath, $uri))) { | |
return false; | |
} | |
return parent::isStaticFile($sitePath, $siteName, $uri); | |
} | |
/** | |
* 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) | |
{ | |
$path = parent::frontControllerPath($sitePath, $siteName, $uri); | |
if (is_dir($this->fullFilePath($sitePath, $uri))) { | |
$path = $this->fullFilePath($sitePath, $uri) . 'index.php'; | |
} | |
if ($this->isScript($uri)) { | |
$path = $this->fullFilePath($sitePath, $uri); | |
} | |
return $path; | |
} | |
/** | |
* Get the full path to the file | |
* | |
* @param string $path | |
* @param string $uri | |
* @return string | |
*/ | |
public function fullFilePath(string $path, string $uri) : string | |
{ | |
return $path . '/public' . $uri; | |
} | |
/** | |
* Determine if a given string ends with a given substring. | |
* | |
* @param string $haystack | |
* @param string|array $needles | |
* @return bool | |
*/ | |
public static function isScript($haystack) | |
{ | |
$needle = '.php'; | |
return substr($haystack, -strlen($needle)) === (string) $needle; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment