-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalValetDriver.php
More file actions
45 lines (34 loc) · 1.18 KB
/
LocalValetDriver.php
File metadata and controls
45 lines (34 loc) · 1.18 KB
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
<?php
use Valet\Drivers\Specific\BedrockValetDriver;
class LocalValetDriver extends BedrockValetDriver
{
private string $REMOTE_HOST;
private string $URI_PREFIX;
private bool $tryRemoteFallback = false;
public function __construct()
{
// TODO:Get from .env file?
$this->REMOTE_HOST = 'https://webentor-starter-project.dev.webikon.sk/';
$this->URI_PREFIX = '/app/uploads/';
}
public function isStaticFile(string $sitePath, string $siteName, string $uri): bool|string
{
$localFileFound = parent::isStaticFile($sitePath, $siteName, $uri);
if ($localFileFound) {
return $localFileFound;
}
if (str_starts_with($uri, $this->URI_PREFIX)) {
$this->tryRemoteFallback = true;
return rtrim($this->REMOTE_HOST, '/') . $uri;
}
return false;
}
public function serveStaticFile(string $staticFilePath, string $sitePath, string $siteName, string $uri): void
{
if ($this->tryRemoteFallback) {
header("Location: $staticFilePath");
return;
}
parent::serveStaticFile($staticFilePath, $sitePath, $siteName, $uri);
}
}