PHP Classes

File: tests/cli/start.php

Recommend this page to a friend!
  Classes of Scott Arciszewski  >  Chronicle  >  tests/cli/start.php  >  Download  
File: tests/cli/start.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Chronicle
Append arbitrary data to a storage container
Author: By
Last change:
Date: 3 years ago
Size: 1,652 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);
namespace
ParagonIE\Chronicle\CliTests;

use
ParagonIE\Chronicle\Chronicle;
use
ParagonIE\Sapient\CryptographyKeys\SigningSecretKey;

if (
file_exists(__DIR__ . '/client.json')) {
    exit(
0);
}
if (
file_exists(__DIR__ . '/client-admin.json')) {
    exit(
0);
}

require_once
__DIR__ . '/cli-include.php';

Chronicle::getDatabase()->beginTransaction();

$signingKey = SigningSecretKey::generate();
$publicKey = $signingKey->getPublickey()->getString();

$ret = \file_put_contents(
   
__DIR__ . '/client.json',
    \
json_encode([
       
'secret-key' => $signingKey->getString(),
       
'public-key' => $signingKey->getPublickey()->getString()
    ])
);

if (
is_bool($ret)) {
    echo
'Could not save temporary client', PHP_EOL;
   
Chronicle::getDatabase()->rollBack();
    exit(
255);
}

Chronicle::getDatabase()->insert(
   
'chronicle_clients',
    [
       
'isAdmin' => false,
       
'publicid' => 'CLI-testing-user',
       
'publicKey' => $publicKey
   
]
);

$signingKey = SigningSecretKey::generate();
$publicKey = $signingKey->getPublickey()->getString();

$ret = \file_put_contents(
   
__DIR__ . '/client-admin.json',
    \
json_encode([
       
'secret-key' => $signingKey->getString(),
       
'public-key' => $signingKey->getPublickey()->getString()
    ])
);

if (
is_bool($ret)) {
    echo
'Could not save temporary client', PHP_EOL;
   
Chronicle::getDatabase()->rollBack();
    exit(
255);
}

Chronicle::getDatabase()->insert(
   
'chronicle_clients',
    [
       
'isAdmin' => true,
       
'publicid' => 'CLI-admin-user',
       
'publicKey' => $publicKey
   
]
);

Chronicle::getDatabase()->commit();

For more information send a message to info at phpclasses dot org.