Skip to content

Instantly share code, notes, and snippets.

@shiroamada
Forked from veganista/OpenCartValetDriver.php
Last active July 8, 2018 11:12
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save shiroamada/c7f346583516110a59800fcae5bd37c5 to your computer and use it in GitHub Desktop.
Laravel Valet Driver - OpenCart 2.x
<?php
/* Class name is determine the foldername.
* if you have myshop as the folder name, the class name should be MyshopValetDriver.
* The file location you should be save to is ~/.valet/Drivers/MyshopValetDrive.php
* class MyshopValetDriver extends ValetDriver
*/
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)
{
//this is to check is it a opencart 2.x project, to check the file exist
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)) {
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 != '' && $uri != '/' && ! strstr($uri, '&') && ! strstr($uri, '?') && ! strstr($uri, '.php') && ! strstr($uri, 'admin')) {
$_GET['_route_'] = ltrim($uri, '/');
} elseif (strstr($uri, 'admin')) {
return $sitePath . '/admin/index.php';
} 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