5 use mdref\Generator\
{Cls
, Func
};
8 protected string $destination;
10 public function __construct(string $destination = ".") {
11 $this->destination
= $destination;
15 * @param array<string, array<string, \ReflectionFunctionAbstract>> $functions
18 public function generateFunctions(array $functions) : void
{
19 foreach ($functions as $ns => $funcs) {
20 $ns_path = $this->destination
. "/" . strtr($ns, "\\", "/");
21 foreach ($funcs as $fn => $rf) {
22 $fn_file = "$ns_path/$fn.md";
23 printf("Generating %s\n", $fn_file);
24 is_dir($ns_path) ||
mkdir($ns_path, 0770, true);
25 file_put_contents($fn_file, new Func($this, $rf));
31 * @param array<string, array<string, \ReflectionClass>> $classes
34 public function generateClasses(array $classes) : void
{
35 foreach ($classes as $ns => $cls) {
36 $ns_path = $this->destination
. "/" . strtr($ns, "\\", "/");
37 foreach ($cls as $cn => $rc) {
38 $cn_path = "$ns_path/$cn";
39 $cn_file = "$cn_path.md";
40 printf("Generating %s\n", $cn_file);
41 is_dir($ns_path) ||
mkdir($ns_path, 0770, true);
42 file_put_contents($cn_file, new Cls($this, $rc));
43 $this->generateMethods($rc);
48 private function generateMethods(\ReflectionClass
$rc) : void
{
50 foreach ($rc->getMethods(\ReflectionMethod
::IS_PUBLIC
) as $rm) {
51 if ($rm->getDeclaringClass()->getName() === $rc->getName()) {
52 foreach ($rc->getInterfaces() as $ri) {
53 if ($ri->hasMethod($rm->getName())) {
57 $funcs[$rc->getName()][$rm->getName()] = $rm;
60 $this->generateFunctions($funcs);