Created
July 18, 2017 14:12
-
-
Save zeshanshani/12c442e3a25a9807f4a5e810ec54fca0 to your computer and use it in GitHub Desktop.
Valet site change document root using Valet Custom 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 | |
| // Change 'site_folder_name' with your valet site's name, e.g., gutenberg | |
| // Change '/root-folder' with the root folder you want to start | |
| // when you type e.g., gutenberg.dev | |
| 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 ) | |
| { | |
| if ( $siteName === 'site_folder_name' ) { | |
| if ( file_exists( $sitePath . '/' ) ) { | |
| 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 ) | |
| { | |
| if ( file_exists( $sitePath . $uri ) && ! is_dir( $sitePath . $uri ) && pathinfo( $sitePath . $uri )['extension'] != 'php' ) { | |
| return $sitePath . $uri; | |
| } | |
| 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 ) | |
| { | |
| if ( $siteName === 'site_folder_name' ) { | |
| $uri = '/root-folder' . $uri; | |
| } | |
| // The requested resource is a PHP file. | |
| if ( file_exists ( $sitePath . $uri ) && isset( pathinfo( $sitePath . $uri )['extension'] ) ) | |
| { | |
| if ( pathinfo( $sitePath . $uri )['extension'] != 'php' ) { | |
| // Set the content type to 'text/css' | |
| if ( pathinfo( $sitePath . $uri )['extension'] == 'css' ) { | |
| header( 'Content-type: text/css' ); | |
| } | |
| return $sitePath . $uri; | |
| } | |
| } | |
| // The requested resource is a directory and contains a child ‘index.php’ file. | |
| if ( file_exists ( $sitePath . $uri . '/index.php' ) ) | |
| { | |
| return $sitePath . $uri . '/index.php'; | |
| } | |
| // If the path does not exist, serve this default file. | |
| return $sitePath . '/excludes.txt'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment