在 Jenkins 中构建和部署 Zend Framework PHP 应用程序

Mad*_*ort 1 jenkins zend-framework2 phplint

我正在设置 jenkins 作业来构建和部署 Zend Framework 2 php 应用程序。在我的 ant 构建脚本中,我定义了一个用于验证 php 文件的 lint 作业。

构建作业失败,因为 lint 在 ZF2 库文件中检测到错误。

这是 lint 生成的输出:

[apply] PHP Fatal error:  Constructor Zend\Captcha\Factory::factory() cannot be static in /var/lib/jenkins/workspace/XXX/vendor/zendframework/zendframework/library/Zend/Captcha/Factory.php on line 90
[apply] Errors parsing /var/lib/jenkins/workspace/XXX/vendor/zendframework/zendframework/library/Zend/Captcha/Factory.php
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么验证Zend/Captcha/Factory.php fails

ANT 任务如下所示:

    <target name="lint" description="Perform syntax check of sourcecode files">
  <apply executable="php" failonerror="true">
   <arg value="-l" />

   <fileset dir="${basedir}/">
    <include name="**/*.php" />
    <modified />
   </fileset>

   <fileset dir="${basedir}/tests">
    <include name="**/*.php" />
    <modified />
   </fileset>
  </apply>
 </target>
Run Code Online (Sandbox Code Playgroud)

Jur*_*man 5

您的问题是因为 Zend Framework 需要 php 5.3.3 或更高版本。由于您的 Jenkins 机器使用 5.3.2,因此会出现各种问题。其中之一显然是您现在遇到的错误。

我认为您之前没有注意到该错误,因为在开发系统上您安装了 5.3.3+。尝试将您的测试环境更新到较新版本的 php,这将消除此特定问题。

更新

为了澄清我的答案,php 5.3.3 中有一个向后兼容性中断,它会返回到您的环境中。检查此更改日志,尤其是此声明:

向后不兼容的变化:

与命名空间类名的最后一个元素同名的方法将不再被视为构造函数。此更改不会影响非命名空间类。

<?php
namespace Foo;
class Bar {
    public function Bar() {
        // treated as constructor in PHP 5.3.0-5.3.2
        // treated as regular method in PHP 5.3.3
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

对从 5.2.x 迁移没有影响,因为命名空间仅在 PHP 5.3 中引入。

在 的情况下Zend\Captcha\Factory,有一个factory()静态方法,因此您可以调用Zend\Captcha\Factory::factory(). 在 php 4 和 5 到 5.3.2 上,这个方法也被解析为工厂的构造函数。并且构造函数不能是静态的。

在这种情况下,linter 会给你一个致命的错误。