mirror of https://github.com/YGGverse/titan-II.git
ghost
10 months ago
8 changed files with 100 additions and 165 deletions
@ -1,40 +1,39 @@ |
|||||||
# Titan II |
# Titan II |
||||||
|
|
||||||
Gemini Protocol library for PHP. |
Gemini Protocol library for PHP 8 |
||||||
|
|
||||||
- [gemini://gemini.circumlunar.space/](gemini://gemini.circumlunar.space/) |
- [gemini://gemini.circumlunar.space/](gemini://gemini.circumlunar.space/) |
||||||
- [https://gemini.circumlunar.space/](https://gemini.circumlunar.space/) |
- [https://gemini.circumlunar.space/](https://gemini.circumlunar.space/) |
||||||
|
|
||||||
## Basic Implentation |
## Install |
||||||
|
|
||||||
|
1. `composer require yggverse/titan-ii` |
||||||
|
2. `openssl req -x509 -newkey rsa:4096 -keyout key.rsa -out cert.pem -days 3650 -nodes -subj "/CN=127.0.0.1"` |
||||||
|
3. `php server.php` |
||||||
|
4. `gemini://127.0.0.1` |
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
``` |
``` |
||||||
<?php |
<?php |
||||||
|
|
||||||
use TitanII\Request; |
$server = new \YGGverse\TitanII\Server(); |
||||||
use TitanII\Response; |
|
||||||
use TitanII\Server; |
|
||||||
|
|
||||||
$server = new Server(); |
|
||||||
|
|
||||||
$server->setCert('cert.pem'); |
$server->setCert('cert.pem'); |
||||||
$server->setKey('key.rsa'); |
$server->setKey('key.rsa'); |
||||||
|
|
||||||
$server->setHandler(function (Request $request): Response { |
$server->setHandler( |
||||||
$response = new Response(); |
function (\YGGverse\TitanII\Request $request): \YGGverse\TitanII\Response |
||||||
|
{ |
||||||
|
$response = new \YGGverse\TitanII\Response(); |
||||||
|
|
||||||
$response->setCode(20); |
$response->setCode(20); |
||||||
$response->setMeta("text/plain"); |
$response->setMeta('text/plain'); |
||||||
$response->setContent("Hello World!"); |
$response->setContent('Hello World!'); |
||||||
|
|
||||||
return $response; |
return $response; |
||||||
}); |
} |
||||||
|
); |
||||||
|
|
||||||
$server->start(); |
$server->start(); |
||||||
``` |
``` |
||||||
|
|
||||||
## Instructions |
|
||||||
|
|
||||||
1. run `cd test/certs; openssl req -x509 -newkey rsa:4096 -keyout key.rsa -out cert.pem -days 3650 -nodes -subj "/CN=127.0.0.1"` |
|
||||||
2. run `composer install` |
|
||||||
3. run `cd ..; php server.php` |
|
||||||
4. Open `gemini://127.0.0.1` |
|
@ -1,18 +0,0 @@ |
|||||||
{ |
|
||||||
"_readme": [ |
|
||||||
"This file locks the dependencies of your project to a known state", |
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", |
|
||||||
"This file is @generated automatically" |
|
||||||
], |
|
||||||
"content-hash": "1d8aa09a1cb642af953e3d80b990a54a", |
|
||||||
"packages": [], |
|
||||||
"packages-dev": [], |
|
||||||
"aliases": [], |
|
||||||
"minimum-stability": "stable", |
|
||||||
"stability-flags": [], |
|
||||||
"prefer-stable": false, |
|
||||||
"prefer-lowest": false, |
|
||||||
"platform": [], |
|
||||||
"platform-dev": [], |
|
||||||
"plugin-api-version": "2.0.0" |
|
||||||
} |
|
@ -1,44 +0,0 @@ |
|||||||
<?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; |
|
||||||
|
|
||||||
// Make a new server |
|
||||||
$server = new Server(); |
|
||||||
|
|
||||||
// Set the certs. |
|
||||||
$server->setCert(__DIR__ . DIRECTORY_SEPARATOR . 'certs' . DIRECTORY_SEPARATOR . 'cert.pem'); |
|
||||||
$server->setKey(__DIR__ . DIRECTORY_SEPARATOR . 'certs' . DIRECTORY_SEPARATOR . 'key.rsa'); |
|
||||||
|
|
||||||
// Response Body (Gemini Text!) |
|
||||||
$body = <<<GEMINI |
|
||||||
# Titan II Lifts off! |
|
||||||
|
|
||||||
The tower is clear! |
|
||||||
GEMINI; |
|
||||||
|
|
||||||
/** |
|
||||||
* Set a request handler. |
|
||||||
* |
|
||||||
* This function must take a `TitanII\Request` object, and return a `TitanII\Response` object. |
|
||||||
*/ |
|
||||||
$server->setHandler(function (Request $request) use (&$body): Response { |
|
||||||
$response = new Response(); |
|
||||||
|
|
||||||
$response->setMeta('text/gemini'); |
|
||||||
$response->setContent($body); |
|
||||||
|
|
||||||
echo $request; |
|
||||||
|
|
||||||
return $response; |
|
||||||
}); |
|
||||||
|
|
||||||
/** |
|
||||||
* Boot the server! |
|
||||||
*/ |
|
||||||
$server->start(); |
|
Loading…
Reference in new issue