PHP Classes

File: src/Chronicle/Handlers/Mirrors.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Chronicle   src/Chronicle/Handlers/Mirrors.php   Download  
File: src/Chronicle/Handlers/Mirrors.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Chronicle
Append arbitrary data to a storage container
Author: By
Last change:
Date: 1 year ago
Size: 1,703 bytes
 

Contents

Class file image Download
<?php
namespace ParagonIE\Chronicle\Handlers;

use
ParagonIE\Chronicle\{
   
Chronicle,
   
Exception\FilesystemException,
   
Exception\InvalidInstanceException,
   
HandlerInterface
};
use
Psr\Http\Message\{
   
RequestInterface,
   
ResponseInterface
};

/**
 * Class Mirrors
 * @package ParagonIE\Chronicle\Handlers
 */
class Mirrors implements HandlerInterface
{
   
/**
     * @param RequestInterface $request
     * @param ResponseInterface $response
     * @param array $args
     * @return ResponseInterface
     * @throws InvalidInstanceException
     * @throws FilesystemException
     */
   
public function __invoke(
       
RequestInterface $request,
       
ResponseInterface $response,
        array
$args = []
    ):
ResponseInterface {
       
$signingKey = Chronicle::getSigningKey();
        return
Chronicle::getSapient()->createSignedJsonResponse(
           
200,
            [
               
'version' => Chronicle::VERSION,
               
'datetime' => (new \DateTime())->format(\DateTime::ATOM),
               
'status' => 'OK',
               
'public-key' => $signingKey->getPublicKey()->getString(),
               
'results' => $this->getMirrors()
            ],
           
$signingKey
       
);
    }

   
/**
     * @return array
     * @throws InvalidInstanceException
     */
   
protected function getMirrors(): array
    {
       
$mirrors = Chronicle::getDatabase()->run(
           
"SELECT
                url, publickey, comment
            FROM
                 "
. Chronicle::getTableName('mirrors') . "
            ORDER BY sortpriority ASC"
       
);
        if (!
is_array($mirrors)) {
            return [];
        }
        return
$mirrors;
    }
}