-
Notifications
You must be signed in to change notification settings - Fork 1
/
OpenCart3ValetDriver.php
104 lines (94 loc) · 2.59 KB
/
OpenCart3ValetDriver.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
class OpenCart3ValetDriver extends ValetDriver
{
private $frontControllers = ['/admin', '/install'];
/**
* 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 . '/.oc3-valet.json');
}
/**
* 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)
{
if ($this->frontControllerUri($uri) === rtrim($uri, '/')) {
return false;
}
if (! file_exists($staticFilePath = $sitePath . $this->getWebRoot($sitePath) . $uri)) {
return false;
}
return $staticFilePath;
}
/**
* 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)
{
$frontControllerUri = $this->frontControllerUri($uri);
if (! is_null($frontControllerUri)) {
return $sitePath . $this->getWebRoot($sitePath) . $frontControllerUri . '/index.php';
}
return $sitePath . $this->getWebRoot($sitePath) . '/index.php';
}
/**
* @param $uri
*
* @return string|null
*/
public function frontControllerUri($uri)
{
foreach ($this->frontControllers as $frontControllerUri) {
if (startsWith($uri, $frontControllerUri)) {
return $frontControllerUri;
}
}
return null;
}
public function getWebRoot($sitePath)
{
return $this->config($sitePath, 'root', '');
}
/**
* @param $sitePath
*
* @param $key
* @param null $defaultValue
*
* @return mixed
*/
protected function config($sitePath, $key, $defaultValue = null)
{
$configJson = file_get_contents($sitePath . '/.oc3-valet.json');
$config = json_decode($configJson, true);
return $config[$key] ?? $defaultValue;
}
}
if (! function_exists('startsWith')) {
// Function to check string starting with given substring
function startsWith($string, $startString)
{
$len = strlen($startString);
return (substr($string, 0, $len) === $startString);
}
}