Skip to content

Instantly share code, notes, and snippets.

@marktopper
Created September 20, 2016 05:43
Show Gist options
  • Save marktopper/311b2cb001407740605757c447d69882 to your computer and use it in GitHub Desktop.
Save marktopper/311b2cb001407740605757c447d69882 to your computer and use it in GitHub Desktop.
Valet Driver for OS.js (http://os.js.org)
<?php
class OsjsValetDriver 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.'/index.html')
&&
strpos(file_get_contents($sitePath.'/index.html'), '<title>OS.js</title>') !== false
) {
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.'/'.$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 ($uri == '/') {
return $sitePath.'/index.html';
} elseif (substr($uri, 0, 5) == '/API/') {
return $sitePath.'/api.php';
} elseif (substr($uri, 0, 4) == '/FS/') {
return $sitePath.'/fs.php';
}
show_valet_404();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment