[go: up one dir, main page]

Menu

[55c200]: / index.php  Maximize  Restore  History

Download this file

161 lines (129 with data), 4.3 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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/**
* Nwicode
*
* @version 1.2.9
* @author Nwicode SAS <dev@nwicode.com>
*/
global
$_config;
$here = __DIR__;
putenv("TMP={$here}/var/tmp");
$oldUmask = umask(003);
if (!file_exists("./config.php")) {
copy("./config.sample.php", "./config.php");
}
if (!file_exists("./lib/Nwicode/Version.php")) {
copy("./lib/Nwicode/Version.sample.php", "./lib/Nwicode/Version.php");
}
require_once "./config.php";
// PHP Info!
if (($_config["environment"] === "development") && isset($_GET["phpi"])) {
phpinfo();
die;
}
set_time_limit(300);
ini_set("max_execution_time", 300);
umask(0);
setlocale(LC_MONETARY, "en_US");
defined("DS")
|| define("DS", DIRECTORY_SEPARATOR);
defined("APPLICATION_PATH")
|| define("APPLICATION_PATH", realpath(dirname(__FILE__) . "/app"));
// Defining ENV globally!
defined("APPLICATION_ENV")
|| define("APPLICATION_ENV", $_config["environment"]);
// Sourcing default libs!
set_include_path(implode(PATH_SEPARATOR, [
realpath(APPLICATION_PATH . "/../lib"),
]));
/**
*
*/
function dbg()
{
$args = func_get_args();
foreach ($args as $arg) {
file_put_contents(
"/tmp/debug.log",
date("d/m/Y H:i:s") . ": " . print_r($arg, true) . PHP_EOL,
FILE_APPEND);
}
}
// When you need to catch fatal errors create the corresponding config line `$_config["handle_fatal_errors"] = true;`!
if (isset($_config["handle_fatal_errors"]) &&
$_config["handle_fatal_errors"] === true) {
// Handle fatal errors!
function shutdownFatalHandler()
{
$error = error_get_last();
if ($error !== null) {
ob_clean();
http_response_code(400);
$payload = [
"error" => true,
"fullError" => $error,
"message" => "ERROR: " . str_replace("\n", " - ", $error["message"]),
];
exit(json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
}
// Handle fatal errors!
register_shutdown_function("shutdownFatalHandler");
} else {
// Handling max memory size issues only!
register_shutdown_function(function () {
$error = error_get_last();
if ($error !== null) {
if (preg_match("/Allowed memory size/im", $error["message"])) {
ob_clean();
http_response_code(400);
$payload = [
"error" => true,
"fullError" => $error,
"message" => "ERROR: " . str_replace("\n", " - ", $error["message"]),
];
exit(json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
}
});
}
// Running!
try {
require_once "./lib/Zend/Application.php";
if (!empty($_SERVER["HTTP_ORIGIN"])) {
header("Access-Control-Allow-Origin: {$_SERVER["HTTP_ORIGIN"]}");
header("Access-Control-Allow-Credentials: true", true);
header("Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS", true);
header("Access-Control-Allow-Headers: Origin, X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept, Pragma, Set-Cookie", true);
header("Access-Control-Max-Age: 86400", true);
}
// Initializing the application!
$ini = is_readable(APPLICATION_PATH . "/configs/app.ini") ?
APPLICATION_PATH . "/configs/app.ini" : APPLICATION_PATH . "/configs/app.sample.ini";
$application = new Zend_Application(
$_config["environment"],
[
"config" => [
$ini,
APPLICATION_PATH . "/configs/resources.cachemanager.ini",
],
]
);
$config = new Zend_Config($application->getOptions(), true);
Zend_Registry::set("config", $config);
Zend_Registry::set("_config", $_config);
session_cache_limiter(false);
$application->bootstrap()->run();
} catch (\Exception $e) {
ob_clean();
http_response_code(400);
$payload = [
"error" => true,
"message" => ($e->getPrevious()) ?
$e->getPrevious()->getMessage() : $e->getMessage(),
];
exit("<pre>" . json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
// Revert umask!
umask($oldUmask);