infusionsoft / infusionsoft-php

PHP client library for the Infusionsoft API.
https://developer.infusionsoft.com/
Other
129 stars 126 forks source link

PHP8.0 NativeParser issue #287

Closed brumiser1550 closed 3 months ago

brumiser1550 commented 3 years ago

I have recently upgraded to PHP8 from PHP7.2 and have started to encounter errors with the returned results from the SDK.

As I understand and have been relying on, any date/datetime field in Keap is supposed to return as a DateTime object. This functionality is what breaks now.

The problem exists somewhere in the NativeParser class that is used because when I force use of XmlReaderParser everything returns as expected.

The issue comes about when a value of 0 comes back through the xml. I have found this issue with the Yes/No and the Whole Number field types in Keap.

Here is an example of the raw xml. <?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><array><data><value><struct><member><name>_AccountStalled</name><value><i4>0</i4></value></member><member><name>_LastUpdated1</name><value><dateTime.iso8601>20210920T00:00:00</dateTime.iso8601></value></member><member><name>Id</name><value><i4>7</i4></value></member><member><name>LastUpdated</name><value><dateTime.iso8601>20210920T16:54:17</dateTime.iso8601></value></member></struct></value></data></array></value></param></params></methodResponse>

When using NatveParser I get back a response of

[0] => Array
        (
            [_AccountStalled] => 0
            [_LastUpdated1] => stdClass Object
                (
                    [scalar] => 20210920T00:00:00
                    [xmlrpc_type] => datetime
                    [timestamp] => 1632096000
                )

            [Id] => 7
            [LastUpdated] => stdClass Object
                (
                    [scalar] => 20210920T16:54:17
                    [xmlrpc_type] => datetime
                    [timestamp] => 1632156857
                )

        )

When I use XmlReaderParser I get back

[0] => Array
        (
            [_AccountStalled] => 0
            [_LastUpdated1] => DateTime Object
                (
                    [date] => 2021-09-20 00:00:00.000000
                    [timezone_type] => 3
                    [timezone] => UTC
                )

            [Id] => 7
            [LastUpdated] => DateTime Object
                (
                    [date] => 2021-09-20 16:54:17.000000
                    [timezone_type] => 3
                    [timezone] => UTC
                )

        )
ryanlholt commented 2 years ago

@brumiser1550 Could this possibly have something to do with the most recent PR that was merged? Looks like it bumped the lstrojny/fxmlrpc dependency up to version 0.20.0.

brumiser1550 commented 2 years ago

@RyanLHolt Not entirely sure when this was introduced, but your comment gave me renewed interest in this issue. I investigate the Native Parser and found what I believe is a bug in the logic. I have created a pull request https://github.com/lstrojny/fxmlrpc/pull/85 to address the issue

brumiser1550 commented 3 months ago

My fix in case anybody else comes across this is to override the Serializer class.

class InfusionsoftSerializer implements SerializerInterface
{

    /**
     * @param string $method
     * @param string $uri
     * @param array $params
     * @param ClientInterface $client
     * @return mixed|void
     * @throws HttpException
     */
    public function request($method, $uri, $params, ClientInterface $client)
    {
        // Although we are using fXmlRpc to handle the XML-RPC formatting, we
        // can still use Guzzle as our HTTP client which is much more robust.
        try {
            $transport = $client->getXmlRpcTransport();

            // TODO: this has the possibility of using NativeParser which is broken
            // if(extension_loaded('xmlrpc')) {
            //      $parser = new BestParserDelegate();
            //  }
            // Because NativeParser is busted, explicitly use the working parser class
            $parser = new XmlReaderParser(true);

            $client = new Client($uri, $transport, $parser);

            $response = $client->call($method, $params);

            return $response;
        } catch (fXmlRpcException $e) {
            throw new HttpException($e->getMessage(), $e->getCode(), $e);
        }
    }

}

# Example usage
$this->keap   = new Infusionsoft($config);
$this->keap->setSerializer(new InfusionsoftSerializer());
$this->keap->setDebug(true);
$this->keap->setToken($token);
brumiser1550 commented 3 months ago

@ROMzombie Since I just saw you active on this SDK I am pinging you on this. This issue breaks the SDK and the fact that nobody else has recognized this after 3 years is disconcerting so hoping to provide some visibility on it. With all of the commotion around API key changes and part of the recommendation being to use this SDK, it should at least be in working order from a bare install. Any chance we can see a change in this? I have pushed a new issue on the fxmlrpc package as well. I have started a conversation in the FB API Group as well.