Liaison-Views.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\View $v */
$v = \Lia\Addon\View::from($lia);
?>
# Views
Views are reusable PHP files and Callables that produce string output, typically producing HTML.
There are three TYPEs of views:
- `main`: When the view is loaded, associated CSS & Javascript files are loaded as well. `main` views have a base dir, then the view name is a relative path (*without extension*).
- `file`: The view points to an individual PHP file. No CSS or JS is loaded automatically.
- `callable`: The view points to a callable that returns a string. No CSS or JS is loaded automatically.
Example:
View dir: `MyPackage/view`
View name: `theme/page_header`
Files Loaded (*within the view dir*):
- `theme/page_header.php`
- `theme/page_header.css`
- `theme/page_header.js`
- `theme/page_header/*.css`
- `theme/page_header/*.js`
<?php
foreach ($v->views as $key => $view_list){
if ($key==null)continue;
echo "\n## Views for package '$key'\n";
foreach($view_list as $view_name=>$view){
if ($view['type'] == 'main'){
$rel_path = $ext->get_rel_path(realpath($view['dir']), $base_dir);
echo "- `$view_name` (*type: main*), (*dir: $rel_path*)\n";
$files = \Lia\Addon\View::from($lia)->get_resource_file_list($view['dir'], $view_name);
foreach ($files as $f){
echo " - `".$ext->get_rel_path(realpath($f), $base_dir)."`\n";
}
} else if ($view['type'] == 'file'){
$rel_path = $ext->get_rel_path(realpath($view['file']), $base_dir);
echo "- `$view_name` (*type: file*), (*file: $rel_path*)\n";
} else if ($view['type'] == 'callable'){
echo "- `$view_name` (*type: callable*)\n";
$c = $view['callable'];
if ($c instanceof Closure){
$refc = new \ReflectionFunction($c);
echo " - Anonymous Function defined in: `".$ext->get_rel_path($refc->getFilename(), $base_dir)."` on line ".$refc->getStartLine()."\n";
// could use getDocComment() to provide further information, but I think this is fine for now.
} else if (is_string($c)) {
echo " - Function name: `$c(...)`\n";
} else if (is_array($c)) {
if (count($c)==2 && is_object($c[0]) && is_string($c[1])){
echo " - Object method: `".get_class($c[0]).'->'.$c[1]."(...)`\n";
} else {
echo " - (*details unavailable*)\n";
}
} else {
echo " - (*details unavailable*)\n";
}
//[type] => callable
//[callable] => Closure#778
//[name] => one
} else {
echo "- `$view_name` (*type: unknown/error*)\n";
}
}
}
//$lia->dump($v->views['site']['one']);
//return;
//print_r($v->views);
?>