anshu-krishna / template-server
A light-weight framework for serving webpages based on templates
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:framework
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_vars
list withvar1
as key.'@var2=pattern'
: matchesRegExp
defined bypattern
. The matched value is assigned toRouter::$path_vars
list withvar2
as key.'@var3~pattern'
: matchesRegExp
defined bypattern
with case-insensitive flag. The matched value is assigned toRouter::$path_vars
list withvar3
as key.