forked from samweru-zz/blockly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
46 lines (35 loc) · 1.12 KB
/
bootstrap.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
<?php
use Strukt\Core\Registry;
use Strukt\Event\Event;
use Strukt\Fs;
$loader = require "vendor/autoload.php";
$loader->add('Blockly', "src/");
$registry = Registry::getInstance();
$registry->set("_staticDir", __DIR__."/public/static");
$servReq = Zend\Diactoros\ServerRequestFactory::fromGlobals(
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);
$json = file_get_contents("php://input");
$body = json_decode(str_replace("'", '"', trim($json)), 1);
$servReq = $servReq->withParsedBody($body);
//Dependency Injection
foreach(["NotFound"=>404,
"MethodNotFound"=>405,
"Forbidden"=>403,
"ServerError"=>500,
"Ok"=>200,
"Redirected"=>302,
"NoContent"=>204] as $msg=>$code)
$registry->set(sprintf("Response.%s", $msg), new Event(function() use($code){
$body = "";
if(in_array($code, array(403,404,405,500)))
$body = Fs::cat(sprintf("public/errors/%d.html", $code));
$res = new Zend\Diactoros\Response();
$res = $res->withStatus($code);
$res->getBody()->write($body);
return $res;
}));