Skip to content

Instantly share code, notes, and snippets.

@rahmanramsi
Last active August 29, 2025 08:17
Show Gist options
  • Save rahmanramsi/a968cdf9aef2977bedc0445545b34cc4 to your computer and use it in GitHub Desktop.
Save rahmanramsi/a968cdf9aef2977bedc0445545b34cc4 to your computer and use it in GitHub Desktop.
OJS Valet Driver
<?php
namespace Valet\Drivers\Custom;
use Valet\Drivers\BasicValetDriver;
class OJSValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri) : bool
{
return file_exists($sitePath.'/config.inc.php') || file_exists($sitePath.'/config.TEMPLATE.inc.php');
}
/**
* 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.'/public'.rtrim($uri, '/').'/index.html')) {
return $staticFilePath;
} elseif (file_exists($staticFilePath = $sitePath.'/public'.rtrim($uri, '/').'/index.php')) {
return $staticFilePath;
} elseif (file_exists($staticFilePath = $sitePath.'/public'.$uri)) {
return $staticFilePath;
} elseif ($this->isActualFile($staticFilePath = $sitePath.$uri)) {
return $staticFilePath;
}
return false;
}
// /**
// * Get the fully resolved path to the application's front controller.
// */
// public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
// {
// return parent::frontControllerPath(
// $sitePath,
// $siteName,
// $uri
// );
// }
/**
* Concatenate the site path and URI as a single file name.
*
* @param string $sitePath
* @param string $uri
* @return string
*/
protected function asActualFile($sitePath, $uri)
{
return $sitePath.$uri;
}
/**
* Format the site path and URI with a trailing "index.php".
*
* @param string $sitePath
* @param string $uri
* @return string
*/
protected function asPhpIndexFileInDirectory($sitePath, $uri)
{
return $sitePath.rtrim($uri, '/').'/index.php';
}
/**
* Format the site path and URI with a trailing "index.html".
*
* @param string $sitePath
* @param string $uri
* @return string
*/
protected function asHtmlIndexFileInDirectory($sitePath, $uri)
{
return $sitePath.rtrim($uri, '/').'/index.html';
}
/**
* Format the incoming site path as root "index.php" file path.
*
* @param string $sitePath
* @return string
*/
protected function asRootPhpIndexFile($sitePath)
{
return $sitePath.'/index.php';
}
/**
* Format the incoming site path as a "public/index.php" file path.
*
* @param string $sitePath
* @return string
*/
protected function asPublicPhpIndexFile($sitePath)
{
return $sitePath.'/public/index.php';
}
/**
* Format the incoming site path as a "public/index.php" file path.
*
* @param string $sitePath
* @return string
*/
protected function asPublicHtmlIndexFile($sitePath)
{
return $sitePath.'/public/index.html';
}
}
@rahmanramsi
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment