生成的WSDL中的Zend soap自动发现和nillable ="true"

Fra*_*o R 4 php soap zend-framework

我正在使用Zend soap自动发现为我的Web服务器生成WSDL文件.问题是每个complexType的每个元素都默认为nillable="true".如何根据需要声明元素?我读了PHPDoc但什么也没找到.

编辑:代码:

class MyService {
    /**
     * Identify remote user.
     *
     * @param LoginReq
     * @return LoginResp
     */
    public function login($request) {
    // Code ....
    }
}

class LoginReq {
    /** @var string */
    public $username;
    /** @var string */
    public $password;
}
class LoginResp {
    /** @var string */
    public $errorCode;
}
Run Code Online (Sandbox Code Playgroud)

生成的WSDL:

  <xsd:complexType name="LoginReq">
    <xsd:all>
      <xsd:element name="username" type="xsd:string" nillable="true"/>
      <xsd:element name="password" type="xsd:string" nillable="true"/>
    </xsd:all>
  </xsd:complexType>
  <xsd:complexType name="LoginResp">
    <xsd:all>
      <xsd:element name="errorCode" type="xsd:string" nillable="true"/>
    </xsd:all>
  </xsd:complexType>
Run Code Online (Sandbox Code Playgroud)

EDIT2:我刚刚发现要将元素声明为您需要使用的必需/可选元素minOccurs/maxOcurrs.它们都默认为1,因此默认情况下每个元素都是必需的.为了声明一个可选元素,您可以使用它来声明它minOccurs="1".Nillable仅用于允许元素为空.同样,我如何将元素声明为可选(因此Zend将minOccurs ="0"添加到该元素)?

jop*_*pke 11

如果您在函数定义中设置了默认值,则它将是可为空的.

public function myMethod($argument = 'hello') {
    // $argument is nillable
}
Run Code Online (Sandbox Code Playgroud)

如果不是这样,你可以用doc块发布你的代码吗?

编辑:您的代码示例澄清了很多.

如果你看看第76行附近的Zend/Soap/Wsdl/Strategy/DefaultComplesType.php,你会看到:

            // If the default value is null, then this property is nillable.
            if ($defaultProperties[$propertyName] === null) {
                $element->setAttribute('nillable', 'true');
            }
Run Code Online (Sandbox Code Playgroud)

这是确定您的"复杂类型"属性是否为空的代码.我会尝试更新您的代码以包含字符串的默认值.就像是:

class LoginReq {
    /** @var string */
    public $username = '';
    /** @var string */
    public $password = '';
}
Run Code Online (Sandbox Code Playgroud)

如果这样做,=== null则应评估为false.但是,请确保您的代码正确处理数据验证.

如果这不起作用,请告诉我!