84a323e522aef859437a51d0443edccdfbf1bba5
5 use mdref\Generator\
{Cls
, Func
};
9 * @param array<string, array<string, \ReflectionFunctionAbstract>> $functions
12 public function generateFunctions(array $functions) : void
{
13 foreach ($functions as $ns => $funcs) {
14 $ns_path = strtr($ns, "\\", "/");
15 foreach ($funcs as $fn => $rf) {
16 $fn_file = "$ns_path/$fn.md";
17 fprintf(STDERR
, "Generating %s\n", $fn_file);
18 is_dir($ns_path) ||
mkdir($ns_path, 0770, true);
19 file_put_contents($fn_file, new Func($this, $rf));
25 * @param array<string, array<string, \ReflectionClass>> $classes
28 public function generateClasses(array $classes) : void
{
29 foreach ($classes as $ns => $cls) {
30 $ns_path = strtr($ns, "\\", "/");
31 foreach ($cls as $cn => $rc) {
32 $cn_path = "$ns_path/$cn";
33 $cn_file = "$cn_path.md";
34 fprintf(STDERR
, "Generating %s\n", $cn_file);
35 is_dir($ns_path) ||
mkdir($ns_path, 0770, true);
36 file_put_contents($cn_file, new Cls($this, $rc));
37 $this->generateMethods($rc);
42 private function generateMethods(\ReflectionClass
$rc) : void
{
44 foreach ($rc->getMethods(\ReflectionMethod
::IS_PUBLIC
) as $rm) {
45 if ($rm->getDeclaringClass()->getName() === $rc->getName()) {
46 foreach ($rc->getInterfaces() as $ri) {
47 if ($ri->hasMethod($rm->getName())) {
51 $funcs[$rc->getName()][$rm->getName()] = $rm;
54 $this->generateFunctions($funcs);