Skip to content

Instantly share code, notes, and snippets.

@vieko
Created January 3, 2018 01:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vieko/a069f81eef03509be953db731a2b1236 to your computer and use it in GitHub Desktop.
Save vieko/a069f81eef03509be953db731a2b1236 to your computer and use it in GitHub Desktop.
Valet Driver for Craft 3 - handles Simple Asset Versioning for local development
<?php
class Craft3ValetDriver 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)
{
return true;
}
/**
* 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 (preg_match('/(.+)\.(?:\d+)\.(js|css|png|jpg|jpeg|gif)$/i', $uri, $matches)) {
if (file_exists($staticFilePath = $sitePath.$matches[1].'.'.$matches[2])) {
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['SCRIPT_FILENAME'] = $sitePath.'/index.php';
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['SCRIPT_NAME'] = '/index.php';
return $sitePath.'/index.php';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment