-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.php
63 lines (50 loc) · 1.67 KB
/
worker.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
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
if (php_sapi_name() == "cli-server") {
$path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
// running under built-in server so
// route static assets and return false
$extensions = array_flip(['jpg', 'png', 'jpeg', 'gif', 'css', 'js', 'woff', 'woff2', 'ttf']);
$ext = pathinfo($path, PATHINFO_EXTENSION);
$env = getenv('DVELUM_ORM_UI_ENV');
if (empty($env)) {
echo 'DVELUM_ORM_UI_ENV variable is not set';
exit();
}
$env = json_decode($env, true);
if (strpos($path, '/js/lib/extjs/') === 0 && isset($extensions[$ext])) {
// proxy ExtJs lib
if ($ext === 'css') {
header('Content-Type: text/css');
} else {
header('Content-Type: ' . mime_content_type($env['dir'] . '/www' . $path));
}
echo file_get_contents($env['dir'] . '/www' . $path);
return true;
}
if (isset($extensions[$ext])) {
return false;
}
define('DVELUM_ORM_IU_DIR', __DIR__);
$app = include $env['dir'] . '/' . $env['bootstrap'];
$app->init();
$envParams = new \Dvelum\Orm\Ui\EnvParams();
$envParams->setDir($env['dir'])
->setBootstrap($env['bootstrap'])
->setApplication($app);
/**
* @todo remove
*/
chdir($env['dir']);
$_SERVER['DVELUM_ORM_UI_ENV'] = $envParams;
$server = new \Dvelum\Orm\Ui\Server();
try {
$response = $server->run(new \Dvelum\Request(), new Dvelum\Response\Response(), $envParams);
} catch (\Throwable $e) {
echo $e->getMessage();
}
} else {
echo 'ORM UI can be used only with cli-server ';
exit();
}