在 laravel 中使用 Laminas SOAP 生成具有复杂子类型的 WSDL

问题描述 投票:0回答:1

我正在尝试弄清楚如何在我的 Laravel 中使用 Laminas SOAP 生成多级 wsdl.. 我也阅读了文档和 chatgpt.. 但我仍然很困惑如何设置,这是链接: https://docs.laminas.dev/laminas-soap/auto-discovery/

这是我的控制器代码:

public function soap()
{
    $server = new Server(
        route('soap-wsdl'),
        [
            'actor' => route('soap-server'),
        ]
    );

    $this->populateServer($server);
    $server->setReturnResponse(true);

    $response = response($server->handle());
    $response->header('Content-Type', 'text/xml');

    return $response;
}

public function wsdl(Request $request)
{
    $wsdl = new AutoDiscover();

    $this->populateServer($wsdl);
    $wsdl->setUri(route('soap-server'))
        ->setServiceName('InaportWSDL');

    return response()->make($wsdl->toXml())
        ->header('Content-Type', 'application/xml');
}

private function populateServer($server)
{
    // Expose a class and its methods:
    $server->setClass(ResponseServices::class);
}

这是我的 ResponseServices 类(或控制器):

class ResponseServices {
/**
 * @param string $user
 * @param string $password
 * @param array $detail
 */
public function entryRpkro($user, $password, $detail)
{
}

}

使用 wizdler 的结果:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
    <entryRpkro xmlns="http://localhost:8000/soap">
        <user>[string]</user>
        <password>[string]</password>
        <detail>[Array]</detail>
    </entryRpkro>
</Body>
</Envelope>

所以我想把这个 wsdl 改成这样:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
    <entryRpkro xmlns="http://localhost:8000/soap">
        <user>[string]</user>
        <password>[string]</password>
        <detail>
          <name>[string]</name>
          <age>[int]</age>
        </detail>
    </entryRpkro>
</Body>
</Envelope>
php laravel soap wsdl laminas
1个回答
0
投票

尝试这样的事情: 创建另一个文件

Details.php
。不要忘记设置命名空间。

class Details
{
    /** @var string */
    public string $name = '';
    /** @var int */
    public string $age = '';
}

将上面的代码更改为如下所示:

class ResponseServices {
    /**
     * @param string $user
     * @param string $password
     * @param \FULL\NAMESPACE\PATH\Details $detail
     */
    public function entryRpkro(string $user, string $password, Details $details)
    {
        // Now you can access $details->name or $details->age
    }
}

请记住,您始终需要在

@param
@return
注释中使用 FQCN,以获得与层板的正确映射。 也许将来你还想调整 laminas 的 complexTypeStrategy 。到目前为止,
ArrayOfTypeComplex
一直最适合我。

© www.soinside.com 2019 - 2024. All rights reserved.