-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
54 lines (39 loc) · 1.41 KB
/
index.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
<?php
use Pdfc\Batch;
use Pdfc\Converter;
use Pdfc\Response;
use Pdfc\Status;
use Pdfc\Validator;
use Respect\Rest\Router;
define('ROOT_DIR', __DIR__);
define('APP_DIR', ROOT_DIR . '/app');
define('APP_WEB', rtrim(dirname($_SERVER['SCRIPT_NAME']), '/'));
$classLoader = require('app/vendor/autoload.php');
$classLoader->add('Pdfc', APP_DIR);
$config = include(ROOT_DIR . '/config.php');
$r = new Router(APP_WEB);
$r->post('/pdf/render', function() {
$request = json_decode(file_get_contents('php://input'), true);
if (!Validator::isValidRequest((array) $request, $_SERVER['REMOTE_ADDR'] ?? '')) {
return '';
}
return Converter::convert($request);
})->accept(Response::pdf());
$r->post('/pdf/batch/render/*', function() {
$request = json_decode(file_get_contents('php://input'), true);
return Batch::render($request);
})->accept(Response::pdf());
$r->post('/pdf/batch/add', function() {
$request = json_decode(file_get_contents('php://input'), true);
if (!Validator::isValidRequest((array) $request, $_SERVER['REMOTE_ADDR'] ?? '')) {
return '';
}
return Batch::add($request);
})->accept(Response::data());
$r->get('/status', function() {
return Status::get();
})->accept(Response::status());
/* deprecated */
$r->get('/pdf/batch/render/*', function($transaction_id) {
return Batch::render(array('transaction_id' => $transaction_id));
})->accept(Response::pdf());