protected function findLinkForClass(\ReflectionClass $rc, Language $lang = null) { $result = null; $type = Type_::fromClass($rc, $lang, $this->project()); if (null !== $type) { $result = $type->link(); } return $result; }
protected function generateIndexFile(Language $lang = null) { $file = $this->createNewFile($this->getDocumentFilename($lang)); if (!\is_resource($file)) { return false; } $header = $this->header(); $footer = $this->footer(); $me = $this; $this->writeTo($file, function () use($footer, $header, $lang, $me) { $doc = $me->docBlock(); $declaredClass = $me->class_(); $classLink = \trim($me->findLinkForClass($declaredClass->reflector(), $lang)); echo $header; echo '<div class="row">'; echo '<ul class="breadcrumbs">'; echo '<li>'; echo '<a href="' . \htmlspecialchars($this->project()->getDocumentFilename($lang)) . '">Home</a>'; echo '</li>'; echo '<li class="unavailable">'; echo '<a href="#">'; echo \htmlentities($me->parseNamespace($declaredClass->reflector()->getNamespaceName())); echo '</a>'; echo '</li>'; echo '<li>'; if ('' !== $classLink) { echo '<a href="' . \htmlspecialchars($classLink) . '">'; } echo \htmlentities($declaredClass->reflector()->getShortName()); if ('' !== $classLink) { echo '</a>'; } echo '</li>'; echo '<li class="current">'; echo '<a href="#">'; echo \htmlentities($me->reflector()->getName()); echo '</a>'; echo '</li>'; echo '</ul>'; echo '<h1>'; echo \htmlentities($me->reflector()->getName()) . '() method'; echo '</h1>'; echo '</div>'; $syntax = $this->syntax($lang); /* @var ReturnTag $returnTag */ $returnTag = Enumerable::create($doc->getTagsByName('return'))->lastOrDefault(); echo '<pre style="background-color: transparent;">'; echo '<code class="php">'; echo $me->parseForHtmlOutput($syntax); echo '</code>'; echo '</pre>'; if ($returnTag instanceof ReturnTag) { /* @var Type_[] $types */ $types = Type_::fromReturnTag($returnTag); if (empty($types)) { $types = [Type_::fromName('mixed')]; } echo '<!-- ' . var_export($types, true) . ' -->'; echo '<h2>Returns</h2>'; echo '<table style="width: 100%;">'; echo '<tbody>'; $typeCount = \count($types); $getTypeName = function (Type_ $type) { $result = $type->name(); if (null !== $type->reflector()) { $result = $type->reflector()->getShortName(); } return $result; }; Enumerable::create($types)->each(function (Type_ $x, IEachItemContext $ctx) use($declaredClass, $getTypeName, $lang, $me, $returnTag, $typeCount) { $typeName = $getTypeName($x); if (0 === \stripos($typeName, "\\")) { if (!interface_exists($typeName) && !trait_exists($typeName) && !class_exists($typeName)) { $newType = $declaredClass->reflector()->getNamespaceName() . $typeName; if (interface_exists($newType) || trait_exists($newType) || class_exists($newType)) { $x = Type_::fromClass(new \ReflectionClass($newType), $lang, $me->project()); $typeName = $getTypeName($x); } } } echo '<td>'; $typeLink = \trim($x->link()); if ('' !== $typeLink) { echo '<a href="' . \htmlspecialchars($typeLink) . '">'; } echo \htmlentities($typeName); if ('' !== $typeLink) { echo '</a>'; } echo '</td>'; if ($ctx->isFirst()) { echo '<td rowspan="' . \trim($typeCount) . '">'; echo $me->parseForHtmlOutput($returnTag->getDescription()); echo '</td>'; } }); echo '</tbody>'; echo '</table>'; } echo <<<'EOT' <script type="text/javascript"> jQuery(document).ready(function() { hljs.initHighlighting(); }); </script> EOT; echo $footer; }); }