workflow/publish: update to php-8.1
[mdref/mdref] / bin / stub2ref
1 #!/usr/bin/env php
2 <?php
3
4 namespace mdref;
5
6 require_once $_composer_autoload_path ?? __DIR__."/../vendor/autoload.php";
7
8 if ($argc < 3) {
9 fprintf(STDERR, "Usage: %s <ns> <stub.php> [<destination>]\n", $argv[0]);
10 exit(1);
11 }
12
13 $namespace = $argv[1];
14 require_once $argv[2];
15 $destination = ($argc > 3) ? $argv[3] : ".";
16
17 if (!is_dir($destination)) {
18 fprintf(STDERR, "Missing $destination/; Making dir.");
19 mkdir($destination) || exit -1;
20 }
21 if (!file_exists("$destination/$namespace.mdref")) {
22 fprintf(STDERR, "Missing $destination/$namespace.mdref; generating default.\n");
23 file_put_contents("$destination/$namespace.mdref", "./%s") || exit -2;
24 }
25 if (!file_exists("$destination/$namespace.md")) {
26 fprintf(STDERR, "Missing $destination/$namespace.mdref; generating default from README.\n");
27 $readme = dirname($argv[2]) . "/README.md";
28 if (!file_exists($readme)) {
29 fprintf(STDERR, "Missing $readme; creating empty $namespace.md");
30 touch("$destination/$namespace.md");
31 } else {
32 link(realpath($readme), "$destination/$namespace.md");
33 }
34 }
35
36 $inspector = new Inspector;
37 $inspector->inspectNamespace($namespace);
38
39 $generator = new Generator($destination);
40 $generator->generateFunctions($inspector->getFunctions());
41 $generator->generateClasses($inspector->getClasses());