-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalValetDriver.php
75 lines (57 loc) · 1.59 KB
/
LocalValetDriver.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
use WPValetBoilerplate\Config;
use WPValetBoilerplate\Debug;
require_once __DIR__ . '/vendor/autoload.php';
Config::setConfigFile( __DIR__ . '/valetbp-config.php' );
Debug::$logfile = Config::get( 'logs.dev' );
/**
* Class LocalValetDriver
*/
class LocalValetDriver extends WordPressValetDriver {
/**
* @var bool
*/
private static $tryRemoteFallback = false;
/**
* @param string $sitePath
* @param string $siteName
* @param string $uri
*
* @return bool|false|string
*/
public function isStaticFile( $sitePath, $siteName, $uri ) {
$localFileFound = parent::isStaticFile( $sitePath, $siteName, $uri );
$remoteFallback = Config::get( 'remote_uploads' );
if ( $localFileFound or ! $remoteFallback ) {
return $localFileFound;
}
if ( self::stringStartsWith( $uri, $remoteFallback['uri_base'] ) ) {
self::$tryRemoteFallback = true;
$remoteHost = Config::get( 'urls.prod.protocol' ) . '//' . Config::get( 'urls.prod.host' );
return rtrim( $remoteHost, '/' ) . $uri;
}
return false;
}
/**
* @param string $staticFilePath
* @param string $sitePath
* @param string $siteName
* @param string $uri
*/
public function serveStaticFile( $staticFilePath, $sitePath, $siteName, $uri ) {
if ( self::$tryRemoteFallback ) {
header( "Location: $staticFilePath" );
} else {
parent::serveStaticFile( $staticFilePath, $sitePath, $siteName, $uri );
}
}
/**
* @param string $string
* @param string $startsWith
*
* @return bool
*/
private static function stringStartsWith( $string, $startsWith ) {
return strpos( $string, $startsWith ) === 0;
}
}