Taeluf's Server | Liaison & Phad
Easy-to-setup server using my foss libs.
For an example setup see test/Server/.
Notice March 24, 2022 !!!
user-ship is not ready yet, so many features of Phad are not valuable. You CAN set-up user hooks yourself, but meh.
Dependencies
- php/liaison: The server framework
- php/lia/phad: A library that compiles pure-html (with some custom tags) into database-connected views. The html may contain php for additional customization.
Extra Stuff
- php/env: for dealing with different environments (localhost/production)
- php/cli: simple cli interface
- php/code-scrawl: Generate this documentation
- php/lexer: Generat ASTs (used by Code Scrawl)
- php/better-regex: Regex stuff ... but I don't think code scrawl uses it any more ...
- php/tester: Testing Library
Notice
I write this for myself. I also write tests & document relatively well. This means it's probably safe for you to use.
However, since I'm currently focused on solving my own needs, I may deprecate or cause breaking changes without warning. Any BIG breaking changes will likely be a new branch with a version bump. But no promises.
Install
composer require taeluf/server v0.1.x-dev
or in your composer.json
{"require":{ "taeluf/server": "v0.1.x-dev"}}
Basic Setup
- create a deliver.php script (see below)
- Create some of the folder structure (better to see test/Server/) for a full example.
- run
vendor/bin/tlfserv
to generate an error page, sitemap (only from phad items), and to re-compile phad items - View documentation for liaison & phad (see above) to figure out how to do everything. Good luck!
Cli Stuff
For additional info, see bin/tlfserv
Execute vendor/bin/tlfserv
to run all commands, or run them individually:
-
tlfserv error-page
: generate an error page -
tlfserv generate-sitemap
: generate a sitemap for PHAD items only (does not sitemap any non-phad routes. Sorry) -
tlfserv recompile-phad
: Recompile all PHAD items.
File/Folder structure
- deliver.php: The script that runs your whole server.
- public: files that are routed by liason automatically
- phad: contains views for phad
- view: contains simple views for liaison
- file: files for direct download (uses a faster router and skips liaison)
- fastroute: scripts for direct execution (uses a faster router and skips liaison)
- cache: cache dir
- sitemap: where the sitemap file goes
Sample deliver.php script
<?php
require(dirname(__DIR__,2).'/vendor/autoload.php');
$debug = true;
$dir = __DIR__;
$pdo = new \PDO('sqlite:'.$dir.'/db.sqlite');
$server = new \Tlf\Server();
$server->file_route($dir.'/file/');
$server->php_route($dir.'/fastroute/');
$server->init($debug);
$server->enable_phad($dir, $pdo);
$lia = $server->lia;
$site = $server->addServer($dir);
$server->deliver();
Classes
class Tlf\Server
A (somewhat) minimal layer on top of Liaison & Phad to make them much easier to setup.
Constants
Properties
-
static public $IS_TLFSERV_CLI = false;
set TRUE to stop deliver() from delivering -
public bool $debug = false;
if true, print error messages & always recompile everything
See init() for initialization. -
public \Env $env;
environment object -
public \Lia $lia;
Liaison object -
public \Phad $phad;
Phad object
Methods
-
public function __construct()
-
public function init($debug=null)
Initialize liaison. -
public function disable_theme()
To disable the theme which generally provides a full HTML doc -
public function file_route($dir)
quickly route to a file in $dir -
public function php_route($dir)
quickly route to a script in $dir -
public function is_request_to(string $url_prefix)
Check if the request uri starts with the given string -
public function addServer($dir,$name=null)
Add a standard Liaison server package for the given dir -
public function enable_phad(string $dir, \PDO $pdo)
-
public function deliver()
Run$lia->deliver()
& automatically handle errors
class Tlf\Server\Helper
Constants
Properties
Methods
-
public function markdown_to_html(string $markdown)
Convert markdown to html, if CommonMark is installed