1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-05 16:40:05 +01:00

tweaks to drivers. add jigsaw

This commit is contained in:
Taylor Otwell
2016-05-05 14:47:34 -05:00
parent 7d8a3e47a6
commit e0da86d2eb
4 changed files with 46 additions and 3 deletions

View File

@@ -0,0 +1,28 @@
<?php
class JigsawValetDriver extends StaticValetDriver
{
/**
* Mutate the incoming URI.
*
* @param string $uri
* @return string
*/
public function mutateUri($uri)
{
return rtrim('/build_local'.$uri, '/');
}
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return void
*/
public function serves($sitePath, $siteName, $uri)
{
return is_dir($sitePath.'/build_local');
}
}

View File

@@ -12,7 +12,7 @@ class StaticValetDriver extends ValetDriver
*/ */
public function serves($sitePath, $siteName, $uri) public function serves($sitePath, $siteName, $uri)
{ {
return file_exists($sitePath.'/index.html'); return $this->isStaticFile($sitePath, $siteName, $uri) !== false;
} }
/** /**

View File

@@ -44,14 +44,15 @@ public static function assign($sitePath, $siteName, $uri)
{ {
$drivers = static::driversIn(VALET_HOME_PATH.'/Drivers'); $drivers = static::driversIn(VALET_HOME_PATH.'/Drivers');
$drivers[] = 'StatamicValetDriver';
$drivers[] = 'LaravelValetDriver'; $drivers[] = 'LaravelValetDriver';
$drivers[] = 'StatamicValetDriver';
$drivers[] = 'JigsawValetDriver';
$drivers[] = 'StaticValetDriver'; $drivers[] = 'StaticValetDriver';
foreach ($drivers as $driver) { foreach ($drivers as $driver) {
$driver = new $driver; $driver = new $driver;
if ($driver->serves($sitePath, $siteName, $uri)) { if ($driver->serves($sitePath, $siteName, $driver->mutateUri($uri))) {
return $driver; return $driver;
} }
} }
@@ -82,6 +83,17 @@ public static function driversIn($path)
return $drivers; return $drivers;
} }
/**
* Mutate the incoming URI.
*
* @param string $uri
* @return string
*/
public function mutateUri($uri)
{
return $uri;
}
/** /**
* Serve the static file at the given path. * Serve the static file at the given path.
* *

View File

@@ -65,6 +65,7 @@ function show_valet_404()
require_once __DIR__.'/drivers/StatamicValetDriver.php'; require_once __DIR__.'/drivers/StatamicValetDriver.php';
require_once __DIR__.'/drivers/LaravelValetDriver.php'; require_once __DIR__.'/drivers/LaravelValetDriver.php';
require_once __DIR__.'/drivers/StaticValetDriver.php'; require_once __DIR__.'/drivers/StaticValetDriver.php';
require_once __DIR__.'/drivers/JigsawValetDriver.php';
$valetDriver = ValetDriver::assign($valetSitePath, $siteName, $uri); $valetDriver = ValetDriver::assign($valetSitePath, $siteName, $uri);
@@ -75,6 +76,8 @@ function show_valet_404()
/** /**
* Dispatch the request. * Dispatch the request.
*/ */
$uri = $valetDriver->mutateUri($uri);
if ($uri !== '/' && $staticFilePath = $valetDriver->isStaticFile($valetSitePath, $siteName, $uri)) { if ($uri !== '/' && $staticFilePath = $valetDriver->isStaticFile($valetSitePath, $siteName, $uri)) {
return $valetDriver->serveStaticFile($staticFilePath, $valetSitePath, $siteName, $uri); return $valetDriver->serveStaticFile($staticFilePath, $valetSitePath, $siteName, $uri);
} }