anshu-krishna / template-server
A light-weight framework for serving webpages based on templates
Installs: 9
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:framework
pkg:composer/anshu-krishna/template-server
Requires
- php: >=8.1
README
KriTS is a light-weight framework for serving webpages based on templates.
Under construction. Check later.
Usage:
<?php use KriTS\Server; use KriTS\RouteExpression as RE; use KriTS\RouteNode as RN; // Initilise the server /* Server::init(?string $templates_path = null, ?string $routes_path = null) : void; */ Server::init(); // Define the routes /* execute(RouteNode $root) : never */ Server::execute(new RN( "root_start", "root", "root_end", new RE('404', new RN( "404_start", "404", "404_end" ))) );
RouteNode:
// Signature: new \KriTS\RouteNode ( array|string|null $pre, array|string|null $here, array|string|null $post, RouteExpression ...$next );
$pre, $here & $post are tempates and can have following values:
- null: It means there is no template
- array: One of more string values as described below
- string: It can be used in following ways
Default: plaintext as template.@file_path: loads file at path'file_path'relative to the defaulttemplates_path#file_path: loads file at absolute path'file_path'
RouteExpression:
// Signature: new \KriTS\RouteExpression( string $exp, private RouteNode|string $route );
$route can be a RouteNode object or a string containing path of route file.
If string starts with '@' then file_path is relative to the default routes_path.
If string starts with '#' then file_path is absolute.
$exp can have following formats:
'plaintext': matches'plaintext''@var1': matches anything. The matched value is assigned toRouter::$path_varslist withvar1as key.'@var2=pattern': matchesRegExpdefined bypattern. The matched value is assigned toRouter::$path_varslist withvar2as key.'@var3~pattern': matchesRegExpdefined bypatternwith case-insensitive flag. The matched value is assigned toRouter::$path_varslist withvar3as key.