Skip to content

Commit

Permalink
Merge pull request #875 from ApiGen/menu-list-feature
Browse files Browse the repository at this point in the history
[Generator] add reflection lists
  • Loading branch information
Tomáš Votruba committed Jun 5, 2017
2 parents f4a3f44 + 9c67857 commit a2f6889
Show file tree
Hide file tree
Showing 53 changed files with 795 additions and 424 deletions.
5 changes: 3 additions & 2 deletions packages/Annotation/src/AnnotationDecorator.php
Expand Up @@ -6,8 +6,9 @@
use ApiGen\Reflection\Contract\Reflection\AbstractReflectionInterface;
use phpDocumentor\Reflection\DocBlock\Tag;

# see: https://github.com/phpDocumentor/TypeResolver#resolving-an-fqsen

/**
* @link https://github.com/phpDocumentor/TypeResolver#resolving-an-fqsen
*/
final class AnnotationDecorator
{
/**
Expand Down
Expand Up @@ -2,7 +2,7 @@

namespace ApiGen\Element\ReflectionCollector;

use ApiGen\Contract\Configuration\ConfigurationInterface;
use ApiGen\Configuration\Configuration;
use ApiGen\Reflection\Contract\Reflection\AbstractReflectionInterface;
use ApiGen\Reflection\Contract\Reflection\Class_\ClassConstantReflectionInterface;
use ApiGen\Reflection\Contract\Reflection\Class_\ClassMethodReflectionInterface;
Expand All @@ -20,7 +20,7 @@
final class AnnotationReflectionCollector extends AbstractReflectionCollector
{
/**
* @var ConfigurationInterface
* @var Configuration
*/
private $configuration;

Expand All @@ -29,7 +29,7 @@ final class AnnotationReflectionCollector extends AbstractReflectionCollector
*/
private $activeAnnotation;

public function __construct(ConfigurationInterface $configuration)
public function __construct(Configuration $configuration)
{
$this->configuration = $configuration;
}
Expand Down
Expand Up @@ -3,7 +3,7 @@
namespace ApiGen\Element\Tests\ReflectionCollector;

use ApiGen\Annotation\AnnotationList;
use ApiGen\Contract\Configuration\ConfigurationInterface;
use ApiGen\Configuration\Configuration;
use ApiGen\Element\ReflectionCollector\AnnotationReflectionCollector;
use ApiGen\ModularConfiguration\Option\AnnotationGroupsOption;
use ApiGen\ModularConfiguration\Option\DestinationOption;
Expand All @@ -20,8 +20,8 @@ final class AnnotationReflectionCollectorTest extends AbstractContainerAwareTest

protected function setUp(): void
{
/** @var ConfigurationInterface $configuration */
$configuration = $this->container->getByType(ConfigurationInterface::class);
/** @var Configuration $configuration */
$configuration = $this->container->getByType(Configuration::class);
$configuration->resolveOptions([
SourceOption::NAME => [__DIR__],
DestinationOption::NAME => TEMP_DIR,
Expand Down
5 changes: 3 additions & 2 deletions packages/Reflection/src/Reflection/Class_/ClassReflection.php
Expand Up @@ -128,12 +128,13 @@ public function getInheritedDescription(): ?string

public function getParentClass(): ?ClassReflectionInterface
{
if (! $this->betterClassReflection->getParentClass()) {
$parentClassName = get_parent_class($this->getName());
if ($parentClassName === false) {
return null;
}

return $this->transformerCollector->transformSingle(
$this->betterClassReflection->getParentClass()
ReflectionClass::createFromName($parentClassName)
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/Reflection/src/TransformerCollector.php
Expand Up @@ -94,7 +94,7 @@ private function hasAllowedAccessLevel($transformedReflection): bool
return true;
}

// hardcoded @todo make service-like and using ConfigurationInterface
// hardcoded @todo make service-like and using Configuration
if ($transformedReflection->isPublic() || $transformedReflection->isProtected()) {
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/StringRouting/tests/Route/SourceCodeRouteTest.php
Expand Up @@ -2,7 +2,7 @@

namespace ApiGen\StringRouting\Tests\Route;

use ApiGen\Contract\Configuration\ConfigurationInterface;
use ApiGen\Configuration\Configuration;
use ApiGen\ModularConfiguration\Option\DestinationOption;
use ApiGen\ModularConfiguration\Option\SourceOption;
use ApiGen\Reflection\Contract\Reflection\Class_\ClassConstantReflectionInterface;
Expand Down Expand Up @@ -30,8 +30,8 @@ final class SourceCodeRouteTest extends AbstractContainerAwareTestCase
protected function setUp(): void
{
$this->stringRouter = $this->container->getByType(StringRouter::class);
/** @var ConfigurationInterface $configuration */
$configuration = $this->container->getByType(ConfigurationInterface::class);
/** @var Configuration $configuration */
$configuration = $this->container->getByType(Configuration::class);
$configuration->resolveOptions([
SourceOption::NAME => [__DIR__],
DestinationOption::NAME => TEMP_DIR
Expand Down
2 changes: 0 additions & 2 deletions packages/ThemeDefault/src/404.latte
Expand Up @@ -3,10 +3,8 @@
{block title}Page not found{/block}

{block content}
<div id="content">
<h1>{include title}</h1>
<p>The requested page could not be found.</p>
<p>You have probably clicked on a link that is outdated and points to a page that does not exist any more or you have made an typing error in the address.</p>
<p>To continue please try to find requested page in the menu or use search field on the top.</p>
</div>
{/block}
11 changes: 2 additions & 9 deletions packages/ThemeDefault/src/@layout.latte
Expand Up @@ -16,11 +16,11 @@
</head>

<body>
{include "partial/menu.latte"}

<div class="container">
<div class="row">
<div class="col-md-12">
{include searchForm}
{include "partial/menu.latte"}
{include content}
{include footer}
</div>
Expand All @@ -37,13 +37,6 @@
</html>


{define searchForm}
<form id="search">
<input type="text" name="q" class="form-control text" placeholder="Search class, function or namespace" autofocus>
</form>
{/define}


{define footer}
<div id="footer">
Generated by <a href="https://github.com/apigen/apigen">ApiGen</a>
Expand Down
3 changes: 0 additions & 3 deletions packages/ThemeDefault/src/annotation-group.latte
@@ -1,10 +1,8 @@
{layout '@layout.latte'}
{var $activePage = 'annotation-group-' . $annotation}

{block title}{$annotation|firstUpper}{/block}

{block content}
<div id="content">
<h1>{include title}</h1>

{if $hasElements}
Expand Down Expand Up @@ -81,7 +79,6 @@
{else}
<p>No elements with <code>@{$annotation}</code> annotation found.</p>
{/if}
</div>
{/block}


Expand Down
61 changes: 30 additions & 31 deletions packages/ThemeDefault/src/class.latte
@@ -1,10 +1,8 @@
{layout '@layout.latte'}
{var $activePage = 'class'}

{block title}Class {$class->getName()}{/block}

{block content}
<div id="content" class="class">
<h1 n:class="$class->isDeprecated() ? deprecated">
Class {if $class->getNamespaceName()}{$class->getNamespaceName()|linkAllNamespaceParts|noescape}\{/if}{$class->getShortName()}
</h1>
Expand All @@ -15,32 +13,34 @@
</div>
{/if}

<dl class="tree" n:ifcontent>
<dd>
{if $class->getParentClass()}
extends
<a href="{$class->getParentClass()|linkReflection}" n:class="$class->getParentClass()->isDeprecated() ? deprecated">
{$class->getParentClass()->getName()}
</a>
{/if}

{if $class->getOwnInterfaces()}
implements
{foreach $class->getOwnInterfaces() as $ownInterface}
<a href="{$ownInterface|linkReflection}" n:class="$ownInterface->isDeprecated() ? deprecated">
{$ownInterface->getName()}
</a>{sep}, {/sep}
{/foreach}
{/if}

{if $class->getTraits()}
uses
{foreach $class->getTraits() as $ownTrait}
<a href="{$ownTrait|linkReflection}" n:class="$ownTrait->isDeprecated() ? deprecated">{$ownTrait->getName()}</a>{sep}, {/sep}
{/foreach}
{/if}
</dd>
</dl>
{if $class->getParentClass() || $class->getOwnInterfaces() || $class->getTraits()}
<dl class="tree">
<dd>
{if $class->getParentClass()}
extends
<a href="{$class->getParentClass()|linkReflection}" n:class="$class->getParentClass()->isDeprecated() ? deprecated">
{$class->getParentClass()->getName()}
</a>
{/if}

{if $class->getOwnInterfaces()}
implements
{foreach $class->getOwnInterfaces() as $ownInterface}
<a href="{$ownInterface|linkReflection}" n:class="$ownInterface->isDeprecated() ? deprecated">
{$ownInterface->getName()}
</a>{sep}, {/sep}
{/foreach}
{/if}

{if $class->getTraits()}
uses
{foreach $class->getTraits() as $ownTrait}
<a href="{$ownTrait|linkReflection}" n:class="$ownTrait->isDeprecated() ? deprecated">{$ownTrait->getName()}</a>{sep}, {/sep}
{/foreach}
{/if}
</dd>
</dl>
{/if}

{define children}
{foreach $children as $child}
Expand Down Expand Up @@ -92,7 +92,7 @@
</table>
{/foreach}

<table n:foreach="$class->getTraits() as $traitName => $trait" class="summary used table table-bordered table-responsive table-striped">
<table n:foreach="$class->getTraits() as $traitName => $trait" class="summary table table-bordered table-responsive table-striped">
<tr><th>Methods used from <a href="{$traitName|linkReflection}#methods">{$traitName}</a> trait</th></tr>
<tr>
<td>
Expand Down Expand Up @@ -156,7 +156,7 @@
</table>
{/foreach}

<table n:foreach="$class->getTraits() as $traitName => $trait" class="summary used table table-bordered table-responsive table-striped">
<table n:foreach="$class->getTraits() as $traitName => $trait" class="summary table table-bordered table-responsive table-striped">
<tr><th>Properties used from <a href="{$traitName|linkReflection}#properties">{$traitName}</a></th></tr>
<tr>
<td>
Expand All @@ -170,5 +170,4 @@
</td>
</tr>
</table>
</div>
{/block}
17 changes: 17 additions & 0 deletions packages/ThemeDefault/src/classes.latte
@@ -0,0 +1,17 @@
{layout '@layout.latte'}

{block title}{$pageTitle}{/block}

{block content}
<h1>{$pageTitle}</h1>

<table class="summary table table-bordered table-responsive table-striped">
{foreach $classes as $class}
<tr>
<td class="name">
<a href="{$class|linkReflection}">{$class->getName()}</a>
</td>
</tr>
{/foreach}
</table>
{/block}
91 changes: 44 additions & 47 deletions packages/ThemeDefault/src/function.latte
@@ -1,64 +1,61 @@
{layout '@layout.latte'}
{var $activePage = 'function'}

{block title}
{if $function->isDeprecated()}Deprecated {/if}Function {$function->getName()}
{/block}

{block content}
<div id="content" class="function">
<h1 n:class="$function->isDeprecated() ? deprecated">Function {$function->getShortName()}</h1>
<h1 n:class="$function->isDeprecated() ? deprecated">Function {$function->getShortName()}</h1>

{if $function->getDescription()}
<div class="description">
{$function|description}
</div>
{/if}
{if $function->getDescription()}
<div class="description">
{$function|description}
</div>
{/if}

<div class="info">
{if $function->getNamespaceName()}<b>Namespace:</b> {$function->getNamespaceName()|linkAllNamespaceParts|noescape}<br>{/if}
{var $filteredAnnotations = ($function->getAnnotations()|annotationFilter: ['param', 'return', 'throws'])}
{foreach $filteredAnnotations as $annotation => $values}
{foreach $values as $value}
<b>{$annotation}{if $value}:{/if}</b>
{$value|annotation:$function|noescape}<br>
{/foreach}
<div class="info">
{if $function->getNamespaceName()}<b>Namespace:</b> {$function->getNamespaceName()|linkAllNamespaceParts|noescape}<br>{/if}
{var $filteredAnnotations = ($function->getAnnotations()|annotationFilter: ['param', 'return', 'throws'])}
{foreach $filteredAnnotations as $annotation => $values}
{foreach $values as $value}
<b>{$annotation}{if $value}:{/if}</b>
{$value|annotation:$function|noescape}<br>
{/foreach}
<a href="{$function|linkSource}" class="open-source-code">Open source code</a>
<br>
</div>
{/foreach}
<a href="{$function|linkSource}" class="open-source-code">Open source code</a>
<br>
</div>

{var $annotations = $function->getAnnotations()}
{var $annotations = $function->getAnnotations()}

<table class="summary table table-responsive table-bordered table-striped" id="parameters" n:if="count($function->getParameters())">
<tr><th>Parameters Summary</th></tr>
<tr n:foreach="$function->getParameters() as $parameter" id="${$parameter->getName()}">
<table class="summary table table-responsive table-bordered table-striped" id="parameters" n:if="count($function->getParameters())">
<tr><th>Parameters Summary</th></tr>
<tr n:foreach="$function->getParameters() as $parameter" id="${$parameter->getName()}">
<td class="name">
<code>
{if $parameter->getTypeHintClassOrInterfaceReflection()}
{$parameter->getTypeHintClassOrInterfaceReflection()|linkReflection}
{else}
{$parameter->getTypeHint()}
{/if}
</code>
</td>
<td class="value"><code>{block|strip}
<span class="property-name">{if $parameter->isPassedByReference()}&amp; {/if}${$parameter->getName()}</span>
{if $parameter->isDefaultValueAvailable()} = {$parameter->getDefaultValueDefinition()|highlightValue:$function|noescape}{elseif $parameter->isVariadic()},…{/if}
{/block}</code></td>
<td>{$parameter|description}</td>
</tr>
</table>

{if isset($annotations['return']) && $annotations['return'][0] !== 'void'}
<table class="summary table table-responsive table-bordered table-striped" id="returns">
<tr><th>Return value Summary</th></tr>
<tr>
<td class="name">
<code>
{if $parameter->getTypeHintClassOrInterfaceReflection()}
{$parameter->getTypeHintClassOrInterfaceReflection()|linkReflection}
{else}
{$parameter->getTypeHint()}
{/if}
</code>
{$annotations['return'][0]|annotation:$function|noescape}
</td>
<td class="value"><code>{block|strip}
<span class="property-name">{if $parameter->isPassedByReference()}&amp; {/if}${$parameter->getName()}</span>
{if $parameter->isDefaultValueAvailable()} = {$parameter->getDefaultValueDefinition()|highlightValue:$function|noescape}{elseif $parameter->isVariadic()},…{/if}
{/block}</code></td>
<td>{$parameter|description}</td>
</tr>
</table>

{if isset($annotations['return']) && $annotations['return'][0] !== 'void'}
<table class="summary table table-responsive table-bordered table-striped" id="returns">
<tr><th>Return value Summary</th></tr>
<tr>
<td class="name">
{$annotations['return'][0]|annotation:$function|noescape}
</td>
</tr>
</table>
{/if}
</div>
{/if}
{/block}

0 comments on commit a2f6889

Please sign in to comment.