Skip to content

Instantly share code, notes, and snippets.

@AugustMiller
Created June 27, 2017 00:36
Show Gist options
  • Save AugustMiller/2ed6b2900f2c9a40a37489097dab8bf2 to your computer and use it in GitHub Desktop.
Save AugustMiller/2ed6b2900f2c9a40a37489097dab8bf2 to your computer and use it in GitHub Desktop.
Kirby Driver for Valet, with support for running the application in a subfolder of the project.
<? class CustomKirbyValetDriver extends ValetDriver
{
/**
* 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 is_dir($sitePath . '/app/kirby');
}
/**
* 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 ($this->isActualFile($staticFilePath = $sitePath . '/app' . $uri)) {
return $staticFilePath;
}
return false;
}
/**
* Determine the name of the directory where the front controller lives.
*
* @param string $sitePath
* @return string
*/
public function frontControllerDirectory($sitePath)
{
return '/app';
}
/**
* 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)
{
// Needed to force Kirby to use *.dev to generate its URLs...
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
if (preg_match('/^\/panel/', $uri)) {
$_SERVER['SCRIPT_NAME'] = '/panel/index.php';
return $sitePath . '/app/panel/index.php';
}
if (file_exists($indexPath = $sitePath . '/app/index.php')) {
$_SERVER['SCRIPT_NAME'] = '/index.php';
return $indexPath;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment