Skip to content

Instantly share code, notes, and snippets.

@robbinbenard
Last active May 2, 2019 08:08
Show Gist options
  • Select an option

  • Save robbinbenard/cdaa72c1bb6fa40dd55f21e836b48cbe to your computer and use it in GitHub Desktop.

Select an option

Save robbinbenard/cdaa72c1bb6fa40dd55f21e836b48cbe to your computer and use it in GitHub Desktop.
<?php
class Mach3frameworkValetDriver 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 (is_link($sitePath.'/mach3framework')) {
$_SERVER['DOCUMENT_ROOT'] = $sitePath;
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 (substr($uri, 0, 15) === '/framework/html') {
$sitePath = $this->resetSitePath($sitePath, $siteName);
return $sitePath . $uri;
}
if (substr($uri, 0, 4) === '/lib') {
$sitePath = $this->resetSitePath($sitePath, $siteName);
return $sitePath.'/applications/website'.$uri;
}
if (file_exists($file = $sitePath . $uri)) {
return $file;
}
return false;
}
/**
* Reset the original site path to mach3framework
*
* @param string $sitePath
* @param string $siteName
* @return string
*/
private function resetSitePath($sitePath, $siteName)
{
return str_replace($siteName, null, $sitePath).'mach3framework';
}
/**
* 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)
{
$sitePath = $this->resetSitePath($sitePath, $siteName);
if (substr($uri, 0, 10) === '/framework') {
return $sitePath . '/framework/index.php';
}
return $sitePath.'/applications/website/index.php';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment