rest.php 1.23 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
21

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

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

30
        $qfq = new QuickFormQuery(['bodytext' => $bodytext]);
31
        $answer = $qfq->rest($restId, $restForm);
Carsten  Rose's avatar
Carsten Rose committed
32

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

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

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

42
43
44
    }
} catch (\Exception $e) {
    $answer[API_MESSAGE] = "Generic Exception: " . $e->getMessage();
Carsten  Rose's avatar
Carsten Rose committed
45
46
47
48
}
header("Content-Type: application/json");
echo json_encode($answer);