32 lines
996 B
PHP
32 lines
996 B
PHP
<?php
|
|
|
|
class LocalValetDriver extends \Valet\Drivers\BasicValetDriver
|
|
{
|
|
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
|
|
{
|
|
$path = trim(parse_url($uri, PHP_URL_PATH), '/');
|
|
|
|
// /portfolio → portfolio.php
|
|
if ($path === 'portfolio') {
|
|
return $this->servePhpFile($sitePath, '/portfolio.php');
|
|
}
|
|
|
|
// /portfolio/{slug} → portfolio-page.php?slug={slug}
|
|
if (preg_match('#^portfolio/([a-z0-9-]+)$#', $path, $m)) {
|
|
$_GET['slug'] = $m[1];
|
|
return $this->servePhpFile($sitePath, '/portfolio-page.php');
|
|
}
|
|
|
|
return parent::frontControllerPath($sitePath, $siteName, $uri);
|
|
}
|
|
|
|
private function servePhpFile(string $sitePath, string $file): string
|
|
{
|
|
$_SERVER['SCRIPT_FILENAME'] = $sitePath . $file;
|
|
$_SERVER['SCRIPT_NAME'] = $file;
|
|
$_SERVER['DOCUMENT_ROOT'] = $sitePath;
|
|
|
|
return $sitePath . $file;
|
|
}
|
|
}
|