Skip to content

Instantly share code, notes, and snippets.

@mityukov
Created March 19, 2018 03:58
Show Gist options
  • Save mityukov/95f790b79faaa8063bf915c9d76c2a8e to your computer and use it in GitHub Desktop.
Save mityukov/95f790b79faaa8063bf915c9d76c2a8e to your computer and use it in GitHub Desktop.
X-Cart 5 Valet driver
<?php
class Xc5ValetDriver 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 file_exists($sitePath . '/classes/XLite.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)
{
$staticFilePath = $sitePath . $uri;
if ($this->isActualFile($staticFilePath)
&& pathinfo($staticFilePath)['extension'] !== 'php'
) {
return $staticFilePath;
}
if ($uri !== '/') {
$_GET['url'] = ltrim($uri, '/');
}
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)
{
$staticFilePath = $sitePath . $uri;
if ($this->isActualFile($staticFilePath)
&& pathinfo($staticFilePath)['extension'] === 'php'
) {
$res = $staticFilePath;
} else {
$res = $sitePath . '/cart.php';
}
$_SERVER['SCRIPT_FILENAME'] = $res;
$_SERVER['PHP_SELF'] = str_replace($sitePath, '', $res);
$_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
$_SERVER['DOCUMENT_ROOT'] = $sitePath;
$_SERVER['QUERY_STRING'] = http_build_query($_GET);
return $res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment