-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalValetDriver.php
59 lines (53 loc) · 1.75 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
<?php
/**
* Defines customizations for this site
* https://laravel.com/docs/5.5/valet#local-drivers
*/
class LocalValetDriver extends LaravelValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
// only route /quiz-embed/ and /ab-embed/ paths here
if(strpos($uri, 'quiz-embed/') || strpos($uri, 'ab-embed/')) {
return true;
}
return false;
}
/**
* Get the fully resolved path to the application's front controller.
* Actually... we're using this as our literal front controller.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string
*/
public function frontControllerPath($sitePath, $siteName, $uri)
{
// set our document root as the $sitePath
$_SERVER["DOCUMENT_ROOT"] = $sitePath;
// load the config
require_once 'wp-content/enp-quiz-config.php';
// see if it's a quiz embed or ab test
if(strpos($uri, 'quiz-embed/')) {
// get the number
$quiz_id = str_replace('/quiz-embed/', '', $uri);
$template = 'quiz';
} else if (strpos($uri, 'ab-embed/')) {
$ab_test_id = str_replace('/ab-embed/', '', $uri);
$template = 'ab-test';
}
// render the file
include $sitePath.'/wp-content/plugins/enp-quiz/public/quiz-take/templates/'.$template.'.php';
// This is our literal frontController, so just return a blank index.php file and be done
return $sitePath.'/wp-content/index.php';
}
}