Last active
March 21, 2017 14:51
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.