使用PHPDoc自动添加Git版本


Automatically Add Git Version with PHPDoc

我想知道是否有人知道将文件/存储库的Git版本插入注释块的方法,以便PHP Doc在生成文档时自动反映它?

phpDocumentor不是将这些信息放入文档的人。。。它必须已经出现在您的文档块中。

听起来你已经习惯了在你的文档块中有$Id$标签,当你检查代码时,这些标签会由CVS和SVN自动填充。。。又名"关键词扩展"。

Git确实允许——https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_keyword_expansion.

您可以创建一个phing脚本,该脚本将查找项目的最新版本。并将令牌替换为每个文件/选定文件中的版本。

例如(我在示例中使用了SVN)在你的芬脚本

获取最新的svn版本

<svnlastrevision workingcopy="${path.to.project.dir}" propertyname="svn.lastrevision" />

在您想要svn版本的文件中,放入一个名为@svn.lastrevision@ 的令牌

以下代码将用版本号替换此令牌

<!-- Apply the version change to all files. -->
        <reflexive>
            <fileset dir="${dir.to.change.version}">
                 <include name="**/*.*" />
            </fileset>
             <filterchain>
                <replacetokens>
                    <token key="svn.lastrevision" value="${svn.lastrevision}" />
                </replacetokens>
            </filterchain>
        </reflexive>