Skip to content

Instantly share code, notes, and snippets.

@RomainMazB
Created June 30, 2020 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RomainMazB/bab965d158bab0b31f6a633e6c8108c9 to your computer and use it in GitHub Desktop.
Save RomainMazB/bab965d158bab0b31f6a633e6c8108c9 to your computer and use it in GitHub Desktop.
Place this file into your Laravel Valet's Drivers directory to work with Thelia installation without any additionnal project configuration
<?php
class TheliaValetDriver 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)
{
if (file_exists($sitePath.'/Thelia')) {
return true;
}
return false;
}
/**
* 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 (file_exists($staticFilePath = $sitePath . '/web/' . $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)
{
if (substr($uri, 0, 14) === '/index_dev.php') {
/**
* Valet runs from a specific PHP file called "server.php"
* This resets the $_SERVER environement variables to what they should be
* Only needed on dev mode
*/
$_SERVER['DOCUMENT_URI'] =
$_SERVER['SCRIPT_FILENAME'] =
$_SERVER['SCRIPT_NAME'] =
$_SERVER['PHP_SELF'] = '/index_dev.php';
return $sitePath . '/web/index_dev.php';
}
return $sitePath . '/web/index.php';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment