Skip to content

Instantly share code, notes, and snippets.

@gilbitron
Last active May 24, 2017 11:56
Show Gist options
  • Save gilbitron/67a7c3ed64e890a593f1ddb6582add79 to your computer and use it in GitHub Desktop.
Save gilbitron/67a7c3ed64e890a593f1ddb6582add79 to your computer and use it in GitHub Desktop.
A generic PHP driver for Laravel Valet
<?php
class PhpValetDriver 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)
{
if (file_exists($sitePath.'/index.php')) {
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)
{
$ext = pathinfo($uri, PATHINFO_EXTENSION);
$staticPath = $sitePath.'/'.$uri;
if (file_exists($staticPath) && $ext && in_array($ext, $this->validExtensions())) {
return $staticPath;
}
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)
{
return $sitePath.'/index.php';
}
private function validExtensions()
{
return [
'css',
'js',
'jpg',
'jpeg',
'gif',
'ico',
'png',
'bmp',
'pict',
'csv',
'doc',
'pdf',
'pls',
'ppt',
'tif',
'tiff',
'eps',
'ejs',
'swf',
'midi',
'mid',
'ttf',
'eot',
'woff',
'otf',
'svg',
'svgz',
'webp',
'docx',
'xlsx',
'xls',
'pptx',
'ps',
'jar',
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment