-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
Platform
macOS
Operating system version
macOS Sequoia 15.1.1
System architecture
ARM64 (M1, M2, etc)
Herd Version
1.13.0 (Build: 37)
PHP Version
PHP 8.2.26
Bug description
I wanted to use a custom WordPress multisite driver.
I've copied mine over from my Valet installation, and this worked flawlessly.
Then, after reading the documentation I've tried to add the siteInformation function as documented at https://herd.laravel.com/docs/1/extending-herd/custom-drivers#customize-herds-behaviour.
However it seems like this function siteInformation is never called (used XDebug to check).
Steps to reproduce
Add a custom driver, using the following code:
<?php
namespace Valet\Drivers\Custom;
use Valet\Drivers\BasicValetDriver;
class WordPressMultisiteValetDriver extends BasicValetDriver {
/**
* @var string The public web directory, if deeper under the root directory
*/
protected $public_dir = '';
/**
* Determine if the driver serves the request.
*/
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return file_exists($sitePath.'/wp-config.php') || file_exists($sitePath.'/wp-config-sample.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(string $sitePath, string $siteName, string $uri) {
$uri = $this->rewriteMultisite($sitePath, $uri);
$sitePath = $this->realSitePath($sitePath);
if ($this->isActualFile($staticFilePath = $sitePath . $uri)) {
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(string $sitePath, string $siteName, string $uri): string {
$this->forceTrailingSlash($uri);
$uri = $this->rewriteMultisite($sitePath, $uri);
$sitePath = $this->realSitePath($sitePath);
return parent::frontControllerPath(
$sitePath,
$siteName,
$this->forceTrailingSlash($uri)
);
}
/**
* Translate the site path to the actual public directory
*
* @param $sitePath
* @return string
*/
protected function realSitePath(string $sitePath): string {
if ($this->public_dir) {
$sitePath .= $this->public_dir;
}
return $sitePath;
}
/**
* Imitate the rewrite rules for a multisite .htaccess
*
* @param $sitePath
* @param $uri
* @return string
*/
protected function rewriteMultisite( string $sitePath, string $uri ): string {
if ( ! file_exists( $sitePath . '/wp-config.php' ) ) {
return $uri;
}
if ( strpos( file_get_contents($sitePath . '/wp-config.php'), 'MULTISITE') !== false ) {
if (preg_match('/^(.*)?(\/wp-(content|admin|includes).*)/', $uri, $matches)) {
//RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
$uri = $matches[2];
} elseif (preg_match('/^(.*)?(\/.*\.php)$/', $uri, $matches)) {
//RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
$uri = $matches[2];
}
}
return $uri;
}
/**
* Redirect to uri with trailing slash.
*/
private function forceTrailingSlash($uri): ?string
{
if (substr($uri, -1 * strlen('/wp-admin')) == '/wp-admin') {
header('Location: '.$uri.'/');
exit;
}
return $uri;
}
public function siteInformation(string $sitePath, string $phpBinary): array
{
echo 'hi';
return [
"Overview" => [
"Site Name" => "Laravel Airport",
"Runway operational" => true,
],
"Flights" => [
"Today" => 10,
"Yesterday" => 5,
"This week" => 22,
],
];
}
}
Make a new project directory. And in there, install WordPress.
Relevant log output
No response
Reactions are currently unavailable