Skip to content

Instantly share code, notes, and snippets.

@danlapteacru
Last active February 19, 2025 07:59
Show Gist options
  • Save danlapteacru/399bbd0e690f7e20a1799cccf32a1bec to your computer and use it in GitHub Desktop.
Save danlapteacru/399bbd0e690f7e20a1799cccf32a1bec to your computer and use it in GitHub Desktop.
`~/.config/valet/Drivers/RadicleValetDriver.php` on Mac or `~/.valet/Drivers/RadicleValetDriver.php` on WSL2
<?php
class RadicleValetDriver 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): bool
{
return file_exists($sitePath . '/public/content/mu-plugins/bedrock-autoloader.php') &&
file_exists($sitePath . '/public/wp-config.php') &&
file_exists($sitePath . '/bedrock/application.php');
}
/**
* 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)/*: string|false */
{
$staticFilePath = $sitePath . '/public' . $uri;
if ($this->isActualFile($staticFilePath)) {
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): string
{
$_SERVER['PHP_SELF'] = $uri;
if (strpos($uri, '/wp/') === 0) {
return is_dir($sitePath . '/public' . $uri)
? $sitePath . '/public' . $this->forceTrailingSlash($uri) . '/index.php'
: $sitePath . '/public' . $uri;
}
return $sitePath . '/public/index.php';
}
/**
* Redirect to uri with trailing slash.
*
* @param string $uri
* @return string
*/
private function forceTrailingSlash($uri)
{
if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') {
header('Location: ' . $uri . '/');
die;
}
return $uri;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment