Skip to content

Instantly share code, notes, and snippets.

@tpmo
Last active May 12, 2016 07:27
Show Gist options
  • Save tpmo/fe6786e1cc412a1267b7d22235a649f8 to your computer and use it in GitHub Desktop.
Save tpmo/fe6786e1cc412a1267b7d22235a649f8 to your computer and use it in GitHub Desktop.
Custom Laravel Valet Driver For Bedrock

Simply copy the WordPressBedrockValetDriver.php into your ~/.valet/Drivers directory.

<?php
class WordPressBedrockValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return void
*/
public function serves($sitePath, $siteName, $uri)
{
return file_exists($sitePath.'/web/index.php') &&
is_dir($sitePath.'/web/wp');
}
/**
* 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.'/web'.$uri) &&
! is_dir($sitePath.'/web'.$uri) &&
pathinfo($sitePath.'/web'.$uri)['extension'] != 'php') {
return $sitePath.'/web'.$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)
{
$_SERVER['PHP_SELF'] = $uri;
$uri = rtrim($uri, '/');
if ($uri == '/') {
return $sitePath.'/web/index.php';
}
if ($uri === '/wp/wp-admin') {
return $sitePath.'/web/wp/wp-admin/index.php';
}
if (file_exists($sitePath.'/web'.$uri) && ! is_dir($sitePath.'/web'.$uri)) {
return $sitePath.'/web'.$uri;
} elseif (file_exists($frontControllerPath = $sitePath.$uri.'/web/index.php')) {
return $frontControllerPath;
} else {
return $sitePath.'/web/index.php';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment