Gemini Protocol library for PHP 8
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
982 B

4 years ago
<?php
namespace TitanII\Test;
require_once(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
use TitanII\Server;
use TitanII\Request;
use TitanII\Response;
4 years ago
// Make a new server
4 years ago
$server = new Server();
4 years ago
// Set the certs.
$server->setCert(__DIR__ . DIRECTORY_SEPARATOR . 'certs' . DIRECTORY_SEPARATOR . 'cert.pem');
$server->setKey(__DIR__ . DIRECTORY_SEPARATOR . 'certs' . DIRECTORY_SEPARATOR . 'key.rsa');
4 years ago
// Response Body (Gemini Text!)
4 years ago
$body = <<<GEMINI
4 years ago
# Titan II Lifts off!
4 years ago
4 years ago
The tower is clear!
4 years ago
GEMINI;
4 years ago
/**
* Set a request handler.
*
* This function must take a `TitanII\Request` object, and return a `TitanII\Response` object.
*/
4 years ago
$server->setHandler(function (Request $request) use (&$body): Response {
$response = new Response();
4 years ago
$response->setMeta('text/gemini');
$response->setContent($body);
echo $request;
return $response;
});
4 years ago
/**
* Boot the server!
*/
$server->start();