-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmockIndex.php
More file actions
91 lines (74 loc) · 3.12 KB
/
mockIndex.php
File metadata and controls
91 lines (74 loc) · 3.12 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
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
<?php
session_start();
require("vendor/autoload.php");
require("www/include/defines.php"); // Re-useable constants
require("www/database/Database.php");
require("www/AddressBook.php");
require("www/AddressBookEntryException.php");
if(defined('ENVIRONMENT'))
{
switch(ENVIRONMENT)
{ // Only enable reporting for the development environment, not production
case 'development':
error_reporting(E_ALL);
break;
case 'testing':
case 'production':
error_reporting(0);
break;
default:
exit('The application environment is not set correctly.');
}
}
$domain = explode('.', "api.propel.com"); // Will be used to route the request
$uri = explode('/', "/address-book"); // Extract URI routing information
$uriLength = $uri ? count($uri) : 0;
$method = POST_STR;
$responseCode = HTTP_RESPONSE_CODE_NOT_FOUND; // Default to not found when routing - this will be overridden should the correct method/path combination be found
$apiKey = getenv(INTERNAL_API_KEY); // Get the API key currently in use to authenticate requests
$header = json_decode($argv[1]);
$contentEncoding = explode(',', $header->{CONTENT_ENCODING_STR}); // Should we receive data encoded, we need to know the encoding so we can decode it
$acceptsEncoding = explode(',', $header->{ACCEPT_ENCODING_STR}); // The client informing us of the encoding it can handle
$encodingCount = sizeof($contentEncoding);
$acceptsEncodingCount = sizeof($acceptsEncoding);
$database = new Data\Database();
try
{
$input = file_get_contents('php://input'); // Read any data sent
for($i=$encodingCount-1; $i > -1; $i--) // Decoding each method received
{
switch($contentEncoding[$i])
{
case GZIP_STR:
$input = gzdecode($input);
break;
case DEFLATE_STR:
$input = gzinflate($input);
break;
}
}
$input = json_decode($input);
}
catch(Exception $e)
{
$input = []; // Default to empty data-set
}
$file = "";
$domainPiece = $domain[0] == WWW_STR ? $domain[1] : $domain[0];
switch($domainPiece) // Routing based on the domain
{
case API_STR:
case API_STAGING_STR:
case API_UAT_STR:
$file = "www/api.php"; // Pass request to the API handler
break;
case PROPEL_TECH_STR:
$file = "www/website.php"; // Load the website
break;
default:
http_response_code($responseCode);
throw new Error(ERR_INVALID_PATH);
}
if($file) // Include the relevant route
require($file);
?>