-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathprod.php
76 lines (69 loc) · 2.1 KB
/
prod.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
<?php
/**
* A Web server script for use in production.
*
* This script is the entry point for an application whilst in production. This script is a base
* guideline and this procedural boot strap is gives you some defaults as a guide.
* You are free to change and configure this script at will.
*
* @global $context
*/
use BEAR\Resource\Exception\MethodNotAllowed;
use BEAR\Resource\Exception\Parameter as BadRequest;
use BEAR\Resource\Exception\ResourceNotFound as NotFound;
//
// Compiled preloader
//
// require dirname(dirname(__DIR__)) . '/var/tmp/preloader/preload.php';
//
// Here we get the production application instance. No $context variable is needed as it defaults to prod.
//
/* @var $app \BEAR\Package\Provide\Application\AbstractApp */
$context = 'prod';
$app = require dirname(__DIR__) . '/instance.php';
//
// Calling the match of a BEAR.Sunday compatible router will give us the $method, $pagePath, $query to be used
// in the page request.
//
list($method, $pagePath, $query) = $app->router->match();
// Remove sub directories from pagePath
$tmp = explode('/', $pagePath);
$pagePath = '';
for ($i = 6, $c = count($tmp); $i < $c; $i++) {
$pagePath .= '/' . $tmp[$i];
}
//var_dump($pagePath); exit;
//
// An attempt to request the page resource is made.
// Upon failure the appropriate error code is assigned and forwarded to ERROR.
//
try {
$app->page = $app->resource->$method->uri('page://self' . $pagePath)->withQuery($query)->eager->request();
} catch (NotFound $e) {
$code = 404;
goto ERROR;
} catch (MethodNotAllowed $e) {
$code = 405;
goto ERROR;
} catch (BadRequest $e) {
$code = 400;
goto ERROR;
} catch (Exception $e) {
$code = 503;
error_log((string)$e);
goto ERROR;
}
//
// OK: Sets the response resources and renders
// ERROR: sets the response code and loads error page.
//
OK: {
$app->response->setResource($app->page)->render()->send();
echo require dirname(__FILE__).'/../../libs/output_data.php';
exit(0);
}
ERROR: {
http_response_code($code);
require dirname(dirname(__DIR__)) . "/var/lib/http_response/{$code}.php";
exit(1);
}