Skip to content

Instantly share code, notes, and snippets.

@nfourtythree
Last active August 4, 2016 07:07
Show Gist options
  • Save nfourtythree/be18e09da2759e7fbd7189e62b69af0f to your computer and use it in GitHub Desktop.
Save nfourtythree/be18e09da2759e7fbd7189e62b69af0f to your computer and use it in GitHub Desktop.
Laravel Valet driver for Craft CMS simple with document root (no locales)
<?php
class CraftLocaleValetDriver 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)
{
$isCraft = is_dir($sitePath.'/craft');
if ($isCraft) {
$_SERVER['DOCUMENT_ROOT'] = $sitePath.'/public';
}
return is_dir($sitePath.'/craft');
}
/**
* 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.'/public'.$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($sitePath, $siteName, $uri)
{
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/public/index.php';
return $sitePath.'/public/index.php';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment