Zend 肥皂自动发现和 nillable=“true"在生成的 WSDL 中 [英] Zend soap autodiscovery and nillable="true" in generated WSDL

查看:38
本文介绍了Zend 肥皂自动发现和 nillable=“true"在生成的 WSDL 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Zend soap 自动发现 来生成一个我的 Web 服务器的 WSDL 文件.问题是每个 complexType 的每个元素都默认为 nillable="true".我如何根据需要声明元素?我阅读了 PHPDoc,但一无所获.

i'm using Zend soap autodiscovery to generate a WSDL file for my web server. The problem is that every element of every complexType defaults to nillable="true". How do i declare elements as required? I read PHPDoc but found nothing.

代码:

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

生成的 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>

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

I just found that to declare an element as required/optional you need to use minOccurs/maxOcurrs. Both of them default to 1, so every element is required by default. In order to declare an optional element, you declare it with minOccurs="1". Nillable is just for allowing elements to be empty. Again, how do i declare an element as optional (so Zend adds minOccurs="0" to that element)?

推荐答案

如果您在函数定义中设置了默认值,它将为 nillable.

if you have a default value set in your function definition, it will be nillable.

public function myMethod($argument = 'hello') {
    // $argument is nillable
}

如果不是这样,你能用文档块发布你的代码吗?

If that isn't it, can you post your code with doc blocks?

您的代码示例阐明了很多.

Your code sample clarifies a lot.

如果您查看 Zend/Soap/Wsdl/Strategy/DefaultComplesType.php 的第 76 行,您会看到:

If you look at Zend/Soap/Wsdl/Strategy/DefaultComplesType.php around line 76, you'll see this:

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

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

That is the code that is determining if your "complex type" attribute is nillable. I would try updating your code to include a default value for the strings. Something like:

class LoginReq {
    /** @var string */
    public $username = '';
    /** @var string */
    public $password = '';
}

如果你这样做,=== null 应该评估为假.不过,请确保您的代码正确处理数据验证.

If you do that, the === null should evaluate to false. Be sure your code handles the data validation properly, though.

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

If that doesn't work, let me know!

这篇关于Zend 肥皂自动发现和 nillable=“true"在生成的 WSDL 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆