Skip to content

Instantly share code, notes, and snippets.

@davidangel
Last active March 21, 2017 14:51
Show Gist options
  • Save davidangel/603ad260b52492bd0a6d701d6aba2491 to your computer and use it in GitHub Desktop.
Save davidangel/603ad260b52492bd0a6d701d6aba2491 to your computer and use it in GitHub Desktop.
Magento 2 Driver for Laravel Valet (adapted from: https://github.com/lexbeelen/laravel-valet-magento2)
<?php
class Magento2ValetDriver 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.'/pub/index.php') &&
file_exists($sitePath.'/bin/magento');
}
/**
* 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)
{
$uri = preg_replace('/^\/static(\/version[\d]+)/', '/static', $uri);
if (file_exists($staticFilePath = $sitePath.'/pub'.$uri)) {
return $staticFilePath;
}
if (strpos($uri, '/static/') === 0) {
$_GET['resource'] = preg_replace('#static/#', '', $uri, 1);
include($sitePath.DIRECTORY_SEPARATOR.'pub/static.php');
exit;
}
if (strpos($uri, '/media/') === 0) {
include($sitePath.DIRECTORY_SEPARATOR.'pub/get.php');
exit;
}
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)
{
return $sitePath.'/pub/index.php';
}
}
@davidangel
Copy link
Author

I needed to add $uri = preg_replace('/^\/static(\/version[\d]+)/', '/static', $uri); to strip the versioned bit of urls. I may actually not have Magento2 configured correctly for dev environment.

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