Last active
July 15, 2016 06:05
-
-
Save pngmark/3de2b34313f704f20a3cbeaf7645b39a to your computer and use it in GitHub Desktop.
This file contains 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 | |
// Original post on: https://medium.com/@theghostcoder/custom-laravel-valet-driver-61ede526861e | |
// Valet drivers are found at ~/.valet/Drivers | |
// You can create/edit Valet Drivers using Terminal with Nano/Vim; or | |
// Show hidden files on your Mac (See https://gist.github.com/markpng/f7ccccbe56acfa0746528e05443844e4) | |
// and use your favorite IDE. | |
class MyValetDriver 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 ) | |
{ | |
// Some structure of your application matches the requested site so use this driver. | |
if ( file_exists ( $sitePath . '/mysite.txt' ) ) return true; | |
return false; | |
} | |
/** | |
* 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 ) | |
{ | |
// A non-PHP static file is found. | |
if ( file_exists ( $staticFilePath = $sitePath . $uri ) && ! is_dir ( $staticFilePath ) && pathinfo ( $staticFilePath )['extension'] != '.php' ) return $staticFilePath; | |
return 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 ) | |
{ | |
// The requested resource is a PHP file. | |
if ( file_exists ( $sitePath . $uri ) && pathinfo ( $sitePath . $uri )['extension'] != 'php' ) return $sitePath . $uri; | |
// The requested resource is a directory and contains a child ‘index.php’ file. | |
else if ( file_exists ( $sitePath . $uri . '/index.php' ) ) return $sitePath . $uri . '/index.php'; | |
// If the path does not exist, serve this default file. | |
else return $sitePath . '/404.php'; | |
} | |
} | |
// CREDITS | |
// Thanks to Cyrod Domingo (http://twitter.com/cyrodjohn) for showing me pathinfo ( $sitePath . $uri )['extension'] != 'php' ) | |
// instead of substr ( $uri, -4 ) == '.php' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original post on: https://medium.com/@theghostcoder/custom-laravel-valet-driver-61ede526861e