Skip to content

Instantly share code, notes, and snippets.

@haipham
Forked from mikkpokk/OpenCartValetDriver.php
Created December 24, 2016 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haipham/975eedee025e8a283e80fa54698eeffc to your computer and use it in GitHub Desktop.
Save haipham/975eedee025e8a283e80fa54698eeffc to your computer and use it in GitHub Desktop.
Laravel Valet Driver - OpenCart 2.x
<?php
class OpenCartValetDriver 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.'/system/engine/action.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)
{
if (file_exists($staticFilePath = $sitePath.$uri)) {
$file_parts = pathinfo($staticFilePath);
if (isset($file_parts) && isset($file_parts['extension']) && $file_parts['extension']) {
return $staticFilePath;
} else {
return false;
}
}
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)
{
$file_parts = pathinfo($sitePath.$uri);
if ($uri != '' && $uri != '/' && ! strstr($uri, '&') && ! strstr($uri, '?') && ! strstr($uri, '.php') && ! strstr($uri, 'admin')) {
$_GET['_route_'] = ltrim($uri, '/');
} elseif (strstr($uri, 'admin')) {
return $sitePath . '/admin/index.php';
} elseif (isset($file_parts) && isset($file_parts['extension']) && $file_parts['extension'] && file_exists($sitePath.$uri)) {
return $sitePath . $uri;
} else {
$parameters[0] = $_SERVER['QUERY_STRING'];
if (strstr($parameters[0], '&')) {
$parameters = explode('&', $parameters[0]);
}
$parameters = array_filter($parameters);
foreach ($parameters as $parameter) {
if (strstr($parameter, '=')) {
$parameter = explode('=', $parameter);
} else {
$parameter[0] = $parameter;
$parameter[1] = '';
}
$_GET[$parameter[0]] = $parameter[1];
}
}
return $sitePath . '/index.php';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment