Methods.md.php.bak

<?php
/**
 * Documentation of Liaison Methods
 * Params are in the `$args` array.
 *
 * @param $lia \Lia instance to document.
 */
$lia = $args['lia'];
$methods = $lia->methods;

$grouped_methods = ['global-function'=>[], 'anonymous-function'=>[]];
foreach ($methods as $m=>$callable){
    if (is_array($callable)){
        $obj = $callable[0];
        $method = $callable[1];
        $callable_description = '';
        if (is_object($obj)){
            $class = get_class($obj);
            $description = "Calls `$class->$method()`";
        } else {
            $description = "Calls `$obj::$method()`";
        }

        $grouped_methods[$class][$m] = $description;
    } else if (is_string($callable)){
        $grouped_methods['global-function'][$m] = 'desc';//$callable;
    } else {
        $grouped_methods['anonymous-function'][$m] = 'desc';//$callable;
    }

}

?>
# Global Liaison Methods
Each of these can be called with `$lia->method(...)`

<?php
foreach ($grouped_methods as $group=>$list){
    $rel_path = null;
    $arg_list = '...';
    if (class_exists($group,true)){
        $parts = explode('\\', $group);
        $name = array_pop($parts);
        $var = '$'.lcfirst($name);

        $php_ext = new \Tlf\Scrawl\FileExt\Php($this);
        $refClass = new ReflectionClass($group);
        $abs_path = $refClass->getFileName();
        $root_path = realpath($this->dir_root);
        if (substr($abs_path,0,strlen($root_path)) == $root_path){
            $rel_path = substr($abs_path,strlen($root_path));
        }
    } else {
        $var = "NOPE";
    }
    echo "\n## $group\n";
    echo "Each Liaison method maps to the following method of `class $group`, represented by `$var`  \n";
    foreach ($list as $method_name=>$description){

        if ($rel_path!=null){
            $ast = $php_ext->parse_file($rel_path);
            $methods = $ast['namespace']['class'][0]['methods'];
            $method = null;
            // print_r($methods);
            // exit;
            var_dump($methods);
            var_dump($method_name);
            exit;
            foreach ($methods as $m){
                if ($m['name']==$method_name){
                    $method = $m;
                     echo "\n\n\n-----------\n\n";
                    print_r($method);
                    exit;
                    break;
                }
            }
            $declarations = [];
            foreach ($method['args'] as $arg){
                $declarations[] = $arg['declaration'];
            }
            $arg_list = implode(', ',$declarations);
        
        }

        echo "- `$method_name(...)` - `$var->$method_name($arg_list)`  \n";
    }
}
?>