move formatting from JS to PHP
[mdref/mdref] / mdref / Generator / Cls.php
1 <?php
2
3 namespace mdref\Generator;
4
5 use mdref\Generator;
6 use phpDocumentor\Reflection\DocBlock;
7
8 class Cls extends Scrap {
9 public function __toString() :string {
10 return parent::toString(__FILE__, __COMPILER_HALT_OFFSET__);
11 }
12 }
13
14 /** @var $gen Generator */
15 /** @var $ref \ReflectionClass */
16 /** @var $doc DocBlock */
17 /** @var $patch callable as function(string, \Reflector) */
18
19 __HALT_COMPILER();
20 # <?php
21 if ($ref instanceof \ReflectionEnum) :
22 ?>enum<?php
23 else :
24 ?><?= implode(" ", \Reflection::getModifierNames($ref->getModifiers()));
25 ?> <?= $ref->isInterface() ? "interface" : "class"
26 ?><?php
27 endif;
28
29 ?> <?= $ref->getName() ?><?php
30
31 if (($parent = $ref->getParentClass())) :
32 ?> extends <?= $parent->getName() ?><?php
33 endif;
34 if (($implements = $ref->getInterfaceNames())) :
35 foreach ($implements as $index => $iface) :
36 foreach ($implements as $implemented) :
37 if ($iface !== $implemented && is_subclass_of($implemented, $iface)) :
38 unset($implements[$index]);
39 endif;
40 endforeach;
41 endforeach;
42 sort($implements);
43 ?> implements <?= implode(", ", $implements); ?><?php
44 endif;
45 ?>
46
47
48 <?= $doc?->getSummary() ?>
49
50
51 <?= $doc?->getDescription() ?>
52
53
54 <?php $patch(SeeAlso::class, $ref) ?>
55
56
57
58 ## Constants:
59
60 <?php
61 if (!($consts = array_filter($ref->getReflectionConstants(), fn($rc) => $rc->getDeclaringClass()->getName() === $ref->getName()))) :
62 ?>None.<?php
63 else:
64 /** @var \ReflectionClassConstant $rc */
65 foreach ($consts as $rc) :
66 ?> * <span class="constant"><?= $rc->getName();
67 ?></span> = <span><?php
68 if ($rc->getValue() instanceof \UnitEnum) :
69 var_export($rc->getValue()->value);
70 else :
71 var_export($rc->getValue());
72 endif;
73 ?><?= "</span>\n"
74 ?><?php
75 endforeach;
76 endif;
77 ?>
78
79
80 ## Properties:
81
82 <?php
83 if (!($props = array_filter($ref->getProperties(), fn($rp) => $rp->getDeclaringClass()->getName() === $ref->getName()))) :
84 ?>None.<?php
85 else:
86 foreach ($props as $rp) :
87 ?> * <?php
88 $patch(Prop::class, $rp);
89 endforeach;
90 endif;
91 ?>
92
93 <?php