SeriousJSON/index.php

68 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2022-11-26 23:51:43 +01:00
<?php
// Autoload files using the Composer autoloader.
require_once __DIR__ . '/vendor/autoload.php';
// First Party
use SeriousJSON\ExampleEntity\Ticket;
use SeriousJSON\ExampleEntity\Grant;
use SeriousJSON\ExampleEntity\Service;
use SeriousJSON\ExampleEntity\User;
use SeriousJSON\JsonDatabase;
$database = new JsonDatabase(__DIR__. DIRECTORY_SEPARATOR .'data');
$database->init();
$service = new Service();
$service->id = "minetest";
$service->token = "45678-hsjsndjs-272892-shgdzusjd-6788";
$user = new User();
$user->id = "bananafish";
$user->serial = '0C:87:64:78';
$user->cert = "Yee Haw";
$grant = new Grant();
$grant->id = uniqid();
$grant->service = $service;
$ticket = new Ticket();
$ticket->id = uniqid();
$ticket->start = 1471111;
$ticket->end = 1474567;
$ticket->user = $user;
$ticket->grant = $grant;
$ticket->groups[] = new User();
$ticket->groups[0]->id = 'baaaa';
$ticket->groups[0]->cert = 'Cat';
2022-11-26 23:51:43 +01:00
$database->save($service);
$database->save($user);
$database->save($grant);
$database->save($ticket);
$database->save($ticket->groups[0]);
2022-11-26 23:51:43 +01:00
echo('<b>Start Time in microseconds: </b>' . microtime(true) . '<br><hr /><br>');
echo('<b>Serialize Ticket with Nesting on</b><br><code>');
echo($ticket->Serialize(true, false, $database));
echo('</code><br><br><b>Deserialize Ticket with Nesting on (vardump)</b><br><code>');
2022-11-26 23:51:43 +01:00
echo(var_dump(Ticket::Deserialize($ticket->Serialize(true), true)));
echo('</code><br><br><b>Re-Serialize Deserialized Ticket with Nesting on</b><br><code>');
echo(Ticket::Deserialize($ticket->Serialize(true), true))->Serialize(true);
echo('</code><br><hr /><br><b>End Time in microseconds: </b>' . microtime(true));
echo('<br><hr><hr><br><b>Start Time in microseconds: </b>' . microtime(true) . '<br><hr /><br>');
echo('<b>Serialize Ticket with Nesting off</b><br><code>');
echo($ticket->Serialize(false, false, $database));
echo('</code><br><br><b>Deserialize Ticket with Nesting off (vardump)</b><br><code>');
2022-11-26 23:51:43 +01:00
echo(var_dump(Ticket::Deserialize($ticket->Serialize(false), false, $database)));
echo('</code><br><br><b>Re-Serialize Deserialized Ticket with Nesting off</b><br><code>');
echo(Ticket::Deserialize($ticket->Serialize(false), false, $database))->Serialize(false);
echo('</code><br><hr /><br><b>End Time in microseconds: </b>' . microtime(true));
?>