PHP Classes

File: src/database.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Chronicle   src/database.php   Download  
File: src/database.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Chronicle
Append arbitrary data to a storage container
Author: By
Last change: Add helper method for determining valid instance names.
Fix settings loading
Concurrent Chronicles

Add support for multiple instances via the ?instance=name parameter.

To implement, add something like this to your local/settings.json in the
instances key:

"public_prefix" => "table_name_prefix"

Then run bin/make-tables.php as normal.

Every instance is totally independent of each other. They have their own

* Clients
* Chain data
* Cross-Signing Targets and Policies
* Replications

If merged, I will document these features and roll it into v1.1.0
Type safety
Date: 1 year ago
Size: 1,065 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

use
ParagonIE\Chronicle\Chronicle;

if (!\
is_readable(CHRONICLE_APP_ROOT . '/local/settings.json')) {
    echo
'Settings are not loaded.', PHP_EOL;
    exit(
1);
}

/** @var array<string, array<string, string>> $settings */
$settings = \json_decode(
    (string) \
file_get_contents(CHRONICLE_APP_ROOT . '/local/settings.json'),
   
true
);
/** @var \ParagonIE\EasyDB\EasyDB $db */
$db = \ParagonIE\EasyDB\Factory::create(
   
$settings['database']['dsn'],
   
$settings['database']['username'] ?? '',
   
$settings['database']['password'] ?? '',
    (array) (
$settings['database']['options'] ?? [])
);

if (!empty(
$_GET['instance'])) {
    if (\
is_string($_GET['instance'])) {
       
/** @var string $instance */
       
$instance = $_GET['instance'];
        if (
Chronicle::isValidInstanceName($instance)) {
            if (\
array_key_exists($instance, $settings['instances'])) {
               
Chronicle::setTablePrefix($settings['instances'][$instance]);
            }
        }
    }
}

Chronicle::setDatabase($db);
return
$db;