Giter VIP home page Giter VIP logo

Comments (16)

Pton avatar Pton commented on August 23, 2024 2

@HKandulla I just wanted to let you know that I am having the exact same use case as you had. PR #39 saved me from having to build it myself, great work 👍

from soap-client.

veewee avatar veewee commented on August 23, 2024

Can you provide some additional information about what you are trying to do?
Maybe a code sample would be handy :)

from soap-client.

HKandulla avatar HKandulla commented on August 23, 2024

Sure. The Service I send my requests to allows me to send:

  1. ns1:DoNotCalltrue</ns1:DoNotCall>
  2. leave it out completely.
    But I am not allowed to send a null value in the form:
  3. <ns1:DoNotCall xsi:nil="true“/>

So my idea was to create a TypeConverter that checks that the provided value is null and creates no tag for that property.

from soap-client.

veewee avatar veewee commented on August 23, 2024

This can be done with a type converter, but then you'll have to add a converter for every type you want to convert this way. In this case: ns1:DoNotCall.
Another option would be a custom middleware that parses the XML and adds the nil attribute wherever you want it. You can probably do this easily by using an xpath expression.

from soap-client.

HKandulla avatar HKandulla commented on August 23, 2024

first of all, tahnks for your quick response!
I created the type converter and defined:

`

public function convertPhpToXml($php)
{
    return !is_null($php)
        ?
        sprintf('<%1$s>%2$s</%1$s>', $this->getTypeName(), $php)
        :
        ''
        ;
}

`

But the generated XML still contains <ns1:CustomerID/>

Any idea how I can eliminate the creation of the tag completely?

Thanks, Hannes

from soap-client.

 avatar commented on August 23, 2024

Hi @veewee,

I figured that the type converter only allows to alter the content and not the tag itself. But I solved it by creating a middleware that removes all empty tags:

`

public function beforeRequest(callable $handler, RequestInterface $request, array $options)
{
    $xml = SoapXml::fromStream($request->getBody());

    // remove all empty nodes
    while (($notNodes = $xml->xpath('//*[not(node())]')) && ($notNodes->length)) {
        foreach($notNodes as $node) {
            $node->parentNode->removeChild($node);
        }
    }

    return $handler(new Request(
        $request->getMethod(),
        $request->getUri(),
        $request->getHeaders(),
        $xml->toStream()
    ), $options);
}

`

Thanks for your help and a great library.

Best, Hannes

from soap-client.

veewee avatar veewee commented on August 23, 2024

No problem! Do you mind adding the Middleware to the package? I am pretty sure it will come in handy for other people as well. Since you already have the code, you'll only have to add some tests and some documentation.

Also, this might be a bit shorter then creating a new request manually:

$request = $request->withBody($xml->toStream());

Thanks!

from soap-client.

 avatar commented on August 23, 2024

sure, I am happy to contribute!
I prepare a PR later tonight.
And thanks for the improvement.

Best, Hannes

from soap-client.

HKandulla avatar HKandulla commented on August 23, 2024

Hi @veewee, just to let you know, I havn't forgotten about this. As soon as I have a little time to write the tests, I create a PR. Best, Hannes

from soap-client.

veewee avatar veewee commented on August 23, 2024

Super, take all the time you need :)

from soap-client.

veewee avatar veewee commented on August 23, 2024

Feedback @HKandulla

I am still busy with the tests on #34. I want to add proper tests that make sure that even nodes with empty child nodes are removed by my middleware. But I definetely do this this week..

from soap-client.

HKandulla avatar HKandulla commented on August 23, 2024

Hi @veewee, finally the PR #39
Best, Hannes

from soap-client.

veewee avatar veewee commented on August 23, 2024

Fixed in #39.

from soap-client.

HKandulla avatar HKandulla commented on August 23, 2024

@Pton Thanks:-)

from soap-client.

ro0NL avatar ro0NL commented on August 23, 2024

@HKandulla 💯 soap is great now :D

from soap-client.

HKandulla avatar HKandulla commented on August 23, 2024

@ro0NL Thanks, glad I could contribute a little.

from soap-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.