【问题标题】:How to prevent ApiGen from using fully-qualified names when replacing @link如何防止 ApiGen 在替换 @link 时使用完全限定名称
【发布时间】:2015-08-13 21:06:09
【问题描述】:

我们目前使用ApiGen 来记录我们的PHP 类。在我们的 doc cmets 中,有很多这样的内联 @link 语句:

{@link AbstractValidatableItem}

在运行 ApiGen 时,语句会展开成这样的链接(请忽略href):

\NSLevel1\NSLevel2\NSLevel3\AbstractValidatableItem

使用许多内联链接,这会产生几乎不可读的文本。因此,我想要一个只包含简单类、接口或方法名称的链接:

AbstractValidatableItem

有没有什么方法可以在不打补丁的情况下使用 ApiGen 做到这一点?我已经试过了

{@link AbstractValidatableItem AbstractValidatableItem}

但这似乎破坏了链接的解析。

【问题讨论】:

    标签: php apigen


    【解决方案1】:

    这不是我首选的解决方案,但我设法快速修补 ApiGen 来为我解决问题:

    --- 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
            );
    

    补丁使它在解析的类上使用getShortName() 而不是getName()

    【讨论】:

      猜你喜欢
      • 2016-04-16
      • 2011-10-02
      • 1970-01-01
      • 2013-06-21
      • 2012-10-12
      • 1970-01-01
      • 2018-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多