2

We currently use ApiGen to document our PHP classes. Inside our doc comments, there are a lot of inline @link statements like this:

{@link AbstractValidatableItem}

When running ApiGen, the statement expands to a link like this (please ignore href):

\NSLevel1\NSLevel2\NSLevel3\AbstractValidatableItem

With many inline links, this creates an almost unreadable text. Therefore, I want to have a link with just the simple class, interface or method name:

AbstractValidatableItem

Is there any way to do this with ApiGen without patching it? I have already tried

{@link AbstractValidatableItem AbstractValidatableItem}

but this seems to break parsing of the link.

Michael Jaros
  • 4,586
  • 1
  • 22
  • 39

1 Answers1

0

This is not my preferred solution, but I managed to quick-patch ApiGen to solve the problem for me:

--- apigen/apigen/src/Templating/Filters/Helpers/ElementLinkFactory.php.orig    Do Aug 13 14:51:13 2015
+++ apigen/apigen/src/Templating/Filters/Helpers/ElementLinkFactory.php Do Aug 13 14:51:33 2015
@@ -39,6 +39,7 @@ class ElementLinkFactory
        $this->linkBuilder = $linkBuilder;
    }

+   private $FULLY_QUALIFIED_NAMES=false;

    /**
     * @return string
@@ -75,7 +76,7 @@ class ElementLinkFactory
    {
        return $this->linkBuilder->build(
            $this->elementUrlFactory->createForClass($reflectionClass),
-           $reflectionClass->getName(),
+           $this->FULLY_QUALIFIED_NAMES ? $reflectionClass->getName() : $reflectionClass->getShortName(),
            TRUE,
            $classes
        );
@@ -89,7 +90,7 @@ class ElementLinkFactory
    {
        return $this->linkBuilder->build(
            $this->elementUrlFactory->createForMethod($reflectionMethod),
-           $reflectionMethod->getDeclaringClassName() . '::' . $reflectionMethod->getName() . '()',
+           ( $this->FULLY_QUALIFIED_NAMES ? $reflectionMethod->getDeclaringClass()->getName() : $reflectionMethod->getDeclaringClass()->getShortName() ) . '::' .  ( $this->FULLY_QUALIFIED_NAMES ? $reflectionMethod->getName() : $reflectionMethod->getShortName()) . '()',
            FALSE,
            $classes
        );

The patch makes it use getShortName() instead of getName() on the resolved classes.

Michael Jaros
  • 4,586
  • 1
  • 22
  • 39