Esempio n. 1
0
 public function post($request, $response, $args)
 {
     $payload = $request->getParsedBody();
     // TODO do propper filtering, checks on garbage or
     // on-insert-umutable data (i.e. the id is autoincremented)
     // this is just a test of the 400 response
     /*new*/
     //$schema = file_get_contents('/var/www/html/glued/glued/Controllers/Api/v0_1/schemas/timepixels.json');
     //print_r($schema);
     //takze normalne pouzij $jsonvr = jsonv::isValid(json_decode($payload), json_decode($schema));
     $jsonvr = jsonv::isValid($payload, json_decode($schema));
     print_r($jsonvr);
     exit;
     /*newend*/
     /*old
             if (!isset($payload['title'], $payload['dt_start'])) {
                 $data['message'] = 'Title and body required';
                 $data['errcode'] = 1;
                 return $this->respond($response, json_encode($data), 400);
             }
     oldend*/
     $data = ['json' => json_encode($payload)];
     $id = $this->container->db->insert('timepixels', $data);
     $payload['id'] = (string) $id;
     return $this->respond($response, json_encode($payload), 201, 'application/json');
 }
Esempio n. 2
0
function runJsonTest($key, $test)
{
    global $totalTestCount;
    global $failedTests;
    $totalTestCount++;
    try {
        if ($test->method == "validate") {
            $result = Validator::validate($test->data, $test->schema);
        } else {
            if ($test->method == "isValid") {
                $result = Validator::isValid($test->data, $test->schema);
            } else {
                if ($test->method == "coerce") {
                    $result = Validator::coerce($test->data, $test->schema);
                } else {
                    $failedTests[$key][] = "Unknown method: {$test->method}";
                    return;
                }
            }
        }
        if (is_object($test->result)) {
            foreach ($test->result as $path => $expectedValue) {
                $actualValue = pointerGet($result, $path, TRUE);
                if (!recursiveEqual($actualValue, $expectedValue)) {
                    $failedTests[$key][] = "{$path} does not match - should be:\n    " . json_encode($expectedValue) . "\nwas:\n    " . json_encode($actualValue);
                }
            }
        } else {
            if (!recursiveEqual($test->result, $result)) {
                $failedTests[$key][] = "{$path} does not match - should be:\n    " . json_encode($test->result) . "\nwas:\n    " . json_encode($result);
            }
        }
    } catch (\Exception $e) {
        $failedTests[$key][] = $e->getMessage();
        $failedTests[$key][] .= "    " . str_replace("\n", "\n    ", $e->getTraceAsString());
    }
}
Esempio n. 3
0
 public function schematest($request, $response)
 {
     $store = new SchemaStore();
     $urlBase = "http://example.com/";
     echo '<h1>test na vlozene schema</h1>';
     $schema_root = json_decode(file_get_contents('/var/www/html/glued/glued/Controllers/Api/v0_1/schemas/timepixels_rootd.json'));
     $schema_user = json_decode(file_get_contents('/var/www/html/glued/glued/Controllers/Api/v0_1/schemas/timepixels_userd.json'));
     echo '<br /><div>zakladni schema s ref udajem pro users</div>';
     echo '<div>' . print_r(json_encode($schema_root), true) . '</div>';
     // priradime to vymyslene adrese http://example.com/test-schema
     $store->add($urlBase . "test-schema", $schema_root);
     // dodame druhou vymyslenou adresu http://example.com/timepixels_user
     $store->add($urlBase . "timepixels_user", $schema_user);
     // vratime schema spojene s prvni adresou, s uz nahrazenym ref
     $schema = $store->get($urlBase . "test-schema");
     echo '<br /><div>s chema s doplnenym subschematem</div>';
     echo '<div>' . print_r(json_encode($schema), true) . '</div>';
     // overeni pres data
     // nejdriv spatna data, protoze users je povinne
     $payload = '
     { "data":
       {
        "title": "New event",
        "dt_start": "2017-02-13 15:00",
        "dt_end": "2017-02-13 16:00"
       }
     }
     ';
     // pak spravna data (pozor na integer id)
     $payload2 = '
     { "data":
       {
        "title": "New event",
        "dt_start": "2017-02-13 15:00",
        "dt_end": "2017-02-13 16:00",
        "users": {
          "data": [{
           "id": 5,
           "name": "kuba"
          }]
        }
       }
     }
     ';
     // validace spatnych dat
     $jsonvr = jsonv::isValid(json_decode($payload), $schema);
     echo '<br /><br /><div>chybny payload je: (' . $payload . ')</div>';
     echo '<div>is valid payloadu vraci:</div>';
     var_dump($jsonvr);
     // validace spravnych dat
     $jsonvr2 = jsonv::isValid(json_decode($payload2), $schema);
     echo '<br /><br /><div>spravny payload2 je: (' . $payload2 . ')</div>';
     echo '<div>is valid payloadu2 vraci:</div>';
     var_dump($jsonvr2);
 }
Esempio n. 4
0
    $this->post('/upload', 'UploadController:post')->setName('upload');
})->add(new AuthMiddleware($container))->add(new \Glued\Middleware\Forms\CsrfViewMiddleware($container))->add($container->csrf);
// group of routes where user must not be signed in to see them
$app->group('', function () {
    $this->get('/auth/signup', 'AuthController:getSignUp')->setName('auth.signup');
    $this->post('/auth/signup', 'AuthController:postSignUp');
    // we only need to set the name once for an uri, hence here not a setName again
    $this->get('/auth/signin', 'AuthController:getSignIn')->setName('auth.signin');
    $this->post('/auth/signin', 'AuthController:postSignIn');
    // we only need to set the name once for an uri, hence here not a setName again
})->add(new GuestMiddleware($container))->add(new \Glued\Middleware\Forms\CsrfViewMiddleware($container))->add($container->csrf);
// APIs
$app->group('', function () {
    $this->get('/api/0.1/test[/{id}]', '\\Glued\\Controllers\\Api\\v0_1\\TestController::get');
    $this->get('/jsonvtest', function ($request, $response) {
        return jsonv::isValid(['a' => 'b'], []);
    });
    // timepixels
    $this->get('/api/0.1/timepixels[/{id}]', 'TimeController:get');
    $this->put('/api/0.1/timepixels[/{id}]', '\\Glued\\Controllers\\Api\\v0_1\\TimePixelsController::put');
    $this->post('/api/0.1/timepixels[/]', 'TimeController:post');
    $this->delete('/api/0.1/timepixels[/{id}]', 'TimeController:delete');
});
// PLAYGROUND
// Pohadkar_Jsv4
$app->get('/playground/pohadkar_jsv4/validationtest', '\\Glued\\Playground\\Pohadkar_Jsv4::validationtest');
$app->get('/playground/pohadkar_jsv4/schematest', '\\Glued\\Playground\\Pohadkar_Jsv4::schematest');
$app->get('/playground/pohadkar_jsv4/schematest2', '\\Glued\\Playground\\Pohadkar_Jsv4::schematest2');
// Killua_Jsv4
$app->get('/playground/killua_jsv4/validationtest', '\\Glued\\Playground\\Killua_Jsv4::validationtest');
$app->get('/playground/killua_jsv4/schematest', '\\Glued\\Playground\\Killua_Jsv4::schematest');