rest.php 1.31 KB
Newer Older
Carsten  Rose's avatar
Carsten Rose committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 17.02.19
 * Time: 15:40
 */

namespace qfq;

use qfq;

require_once(__DIR__ . '/../core/QuickFormQuery.php');
require_once(__DIR__ . '/../core/exceptions/UserFormException.php');
require_once(__DIR__ . '/../core/exceptions/CodeException.php');
require_once(__DIR__ . '/../core/exceptions/DbException.php');

18
19
$restId=array();
$restForm=array();
Carsten  Rose's avatar
Carsten Rose committed
20

Carsten  Rose's avatar
Carsten Rose committed
21
22
$status='HTTP/1.0 409 Bad Request';

Carsten  Rose's avatar
Carsten Rose committed
23
try {
24
    try {
Carsten  Rose's avatar
Carsten Rose committed
25
        $form = OnString::splitPathInfoToIdForm($_SERVER['PATH_INFO'], $restId, $restForm);
26
27
28
29
30
31

        $id=end($restId);
                    // Fake Bodytext setup
        $bodytext = TYPO3_RECORD_ID . '=' . $id . PHP_EOL;
        $bodytext .= TYPO3_FORM . '=' . $form . PHP_EOL;

32
        $qfq = new QuickFormQuery(['bodytext' => $bodytext]);
33
        $answer = $qfq->rest($restId, $restForm);
Carsten  Rose's avatar
Carsten Rose committed
34
        $status='HTTP/1.0 200 OK';
Carsten  Rose's avatar
Carsten Rose committed
35

36
37
    } catch (qfq\CodeException $e) {
        $answer[API_MESSAGE] = $e->formatMessage();
Carsten  Rose's avatar
Carsten Rose committed
38

39
40
    } catch (qfq\UserFormException $e) {
        $answer[API_MESSAGE] = $e->formatMessage();
Carsten  Rose's avatar
Carsten Rose committed
41

42
43
    } catch (qfq\DbException $e) {
        $answer[API_MESSAGE] = $e->formatMessage();
Carsten  Rose's avatar
Carsten Rose committed
44

45
46
47
    }
} catch (\Exception $e) {
    $answer[API_MESSAGE] = "Generic Exception: " . $e->getMessage();
Carsten  Rose's avatar
Carsten Rose committed
48
}
Carsten  Rose's avatar
Carsten Rose committed
49
50

header($status);
Carsten  Rose's avatar
Carsten Rose committed
51
52
53
header("Content-Type: application/json");
echo json_encode($answer);