Liaison-Routes.md.php
<?php
/** @var \Lia $lia */
$lia = $args['lia'];
/** @var string $base_dir */
$base_dir = realpath($args['base_dir']);
/** @var \Tlf\Scrawl $scrawl */
$scrawl = $this;
/** @var \Lia\Ext\Scrawl $ext */
$ext = $args['scrawl_ext'];
/** @var \Lia\Addon\Router $r */
$r = \Lia\Addon\Router::from($lia);
?>
# Routes
Routes connect a URL Request to a target file or callable. Routes can be static patterns (`/blog/some-post/`) or dynamic (`/blog/{postname}/`). Routes can point to `.php` scripts that are executed on request or to static files like `.css`, `.js`, `.png`, `.pdf`, or others. Routes allow `GET` requests by default, and can also allow `POST` requests.
If a route supports both `GET` and `POST`, it will be under each section below.
## POST Routes
<?php
if (count($r->routeMap['POST'])==0)echo "There are no POST routes.\n";
$route_map = $r->routeMap['POST'] ?? [];
$did_get = false;
list_routes:
foreach ($route_map as $path=>$route_list){
if (count($route_list) == 1){
$route = $route_list[0];
$package = is_null($route['package']) ? 'none' : get_class($route['package']) .', '.$route['package']->fqn;
echo "- `".$route['parsedPattern']."`";
if (strpos($route['parsedPattern'],'?')!==false){
$paramaterizedPattern = str_replace(["@POST.", "@GET."], "", $route['pattern']);
echo " (*pattern: `".$paramaterizedPattern."`*), ";
}
if (is_string($route['target'])&&is_file($route['target'])){
echo " (*file: `".$ext->get_rel_path(realpath($route['target']), $base_dir)."`*), (*package: $package*)\n";
} else if (is_callable($route['target'])){
echo " (*callable: ".$ext->get_callable_details($route['target'], $base_dir)."*), (*package: $package*)\n";
} else {
echo " (*target unknown*)";
}
} else {
echo "- `$path` multiple targets:\n";
foreach ($route_list as $route){
$package = is_null($route['package']) ? 'none' : get_class($route['package']).', '.$route['package']->fqn;
$pattern="";
if (strpos($route['parsedPattern'],'?')!==false){
$paramaterizedPattern = str_replace(["@POST.", "@GET."], "", $route['pattern']);
echo " (*pattern: `".$paramaterizedPattern."`*), ";
}
if (is_string($route['target'])&&is_file($route['target'])){
echo " -$pattern (*file: `".$ext->get_rel_path(realpath($route['target']), $base_dir)."`*), (*package: $package*)\n";
} else if (is_callable($route['target'])){
echo " -$pattern (*callable: ".$ext->get_callable_details($route['target'], $base_dir)."*), (*package: $package*)\n";
} else {
echo " (*target unknown*)";
}
}
}
//echo "- `".$route['parsedPattern']."`\n";
}
if ($did_get){goto route_lists_done;}
?>
## GET Routes
<?php
if (count($r->routeMap['POST'])==0)echo "There are no GET routes.\n";
$did_get = true;
$route_map = $r->routeMap['GET']??[];
goto list_routes;
route_lists_done: