stub2ref
[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())) : sort($implements);
35 ?> implements <?= implode(", ", $implements); ?><?php
36 endif;
37 ?>
38
39
40 <?= $doc?->getSummary() ?>
41
42
43 <?= $doc?->getDescription() ?>
44
45
46 <?php $patch(SeeAlso::class, $ref) ?>
47
48
49
50 ## Constants:
51
52 <?php
53 if (!($consts = array_filter($ref->getReflectionConstants(), fn($rc) => $rc->getDeclaringClass()->getName() === $ref->getName()))) :
54 ?>None.<?php
55 else:
56 /** @var \ReflectionClassConstant $rc */
57 foreach ($consts as $rc) :
58 ?> * <span class="constant"><?= $rc->getName();
59 ?></span> = <span><?php
60 if ($rc->getValue() instanceof \UnitEnum) :
61 var_export($rc->getValue()->value);
62 else :
63 var_export($rc->getValue());
64 endif;
65 ?><?= "</span>\n"
66 ?><?php
67 endforeach;
68 endif;
69 ?>
70
71
72 ## Properties:
73
74 <?php
75 if (!($props = array_filter($ref->getProperties(), fn($rp) => $rp->getDeclaringClass()->getName() === $ref->getName()))) :
76 ?>None.<?php
77 else:
78 foreach ($props as $rp) :
79 ?> * <?php
80 $patch(Prop::class, $rp);
81 endforeach;
82 endif;
83 ?>
84
85 <?php