Skip to content

Instantly share code, notes, and snippets.

@LasseRafn
Created August 12, 2016 09:23
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 LasseRafn/86bb26c950ed9e27d33a46bcff389c6d to your computer and use it in GitHub Desktop.
Save LasseRafn/86bb26c950ed9e27d33a46bcff389c6d to your computer and use it in GitHub Desktop.
?php
class Prestashop1ValetDriver extends ValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return boolean
*/
public function serves($sitePath, $siteName, $uri)
{
return file_exists($sitePath . '/classes/PrestaShopAutoload.php')
&& file_exists($sitePath . '/config/config.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 . $uri))
|| (file_exists($staticFilePath = $sitePath . '/install/' . $uri))
|| (file_exists($staticFilePath = $sitePath . '/admin/' . $uri))
|| (file_exists($staticFilePath = $sitePath . '/themes/' . $uri))
) && !is_dir($staticFilePath))
{
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(strpos($uri, '/api') !== false)
{
return $sitePath . '/webservice/dispatcher.php';
}
if(strpos($uri, '/install') !== false)
{
return $sitePath . '/install/index.php';
}
if(strpos($uri, '/install') !== false)
{
return $sitePath . '/install/index.php';
}
if(strpos($uri, '/admin') !== false)
{
$path = $sitePath;
$results = scandir($path);
foreach($results as $result)
{
if( $result === '.' || $result === '..' || strpos($result, 'admin') === false || !is_dir($path . '/' . $result)) continue;
return $path . '/' . $result . '/index.php';
}
return $sitePath . '/admin/index.php';
}
return $sitePath . '/index.php';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment