-
Notifications
You must be signed in to change notification settings - Fork 1
/
FishpigMagento2ValetDriver.php
82 lines (74 loc) · 2.45 KB
/
FishpigMagento2ValetDriver.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
<?php
class FishpigMagento2ValetDriver extends Magento2ValetDriver
{
protected $wpDriver;
/**
* Determine if a uri belongs to WordPress
*
* @param string $uri
* @return boolean
*/
public function isWordPressUri($uri) {
return (stripos($uri, '/wp/index.php') !== false || stripos($uri, 'wp-admin') !== false || stripos($uri, 'wp-login') !== false || stripos($uri, 'wp-content') !== false || stripos($uri, 'wp-includes') !== false);
}
/**
* Instantiate the WordPressValetDriver when required
*
* @return WordPressValetDriver
*/
public function getWordPressValetDriver() {
if(!$this->wpDriver) {
$this->wpDriver = new WordPressValetDriver;
}
return $this->wpDriver;
}
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
if (!file_exists($sitePath.'/wp/wp-content/themes/fishpig/index.php')) {
return false;
}
return parent::serves($sitePath, $siteName, $uri);
}
/**
* 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 the URI contains one of the main WordPress entry points, use the WordPress driver, else use the Magento 2 driver
if($this->isWordPressUri($uri)) {
return $this->getWordPressValetDriver()->isStaticFile($sitePath, $siteName, $uri);
} else {
return parent::isStaticFile($sitePath, $siteName, $uri);
}
}
/**
* 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)
{
// If the URI contains one of the main WordPress entry points, use the WordPress driver, else use the Magento 2 driver
if($this->isWordPressUri($uri)) {
return $this->getWordPressValetDriver()->frontControllerPath($sitePath, $siteName, $uri);
} else {
return parent::frontControllerPath($sitePath, $siteName, $uri);
}
}
}