phplaravellumentwinfield

How to get value from the given object response from Twinfield in Laravel/Lumen?


This is the response when I call the login method from twinfield API. It given the session id and cluster namespace, but the problem is how to get the value from it.

$customerApiConnector = new \PhpTwinfield\ApiConnectors\CustomerApiConnector($login);
print_r($customerApiConnector);die;

Output:

  PhpTwinfield\ApiConnectors\CustomerApiConnector Object
    (
        [service:protected] => PhpTwinfield\Services\ProcessXmlService Object
            (
                [trace] => 1
                [compression] => 32
                [_stream_context] => Resource id #153
                [_soap_version] => 1
                [sdl] => Resource id #154
                [__default_headers] => Array
                    (
                        [0] => SoapHeader Object
                            (
                                [namespace] => http://www.twinfield.com/
                                [name] => Header
                                [data] => Array
                                    (
                                        [SessionID] => f7b4c213-1a01-4c7c-87cb-7de80b1583fe
                                    )

                                [mustUnderstand] => 
                            )

                    )

            )

    )

This is the other object.

Array
(
    [1] => PhpTwinfield\CustomerAddress Object
        (
            [ID:PhpTwinfield\CustomerAddress:private] => 1
            [type:PhpTwinfield\CustomerAddress:private] => invoice
            [default:PhpTwinfield\CustomerAddress:private] => true
            [name:PhpTwinfield\CustomerAddress:private] => Anand
            [contact:PhpTwinfield\CustomerAddress:private] => 
            [country:PhpTwinfield\CustomerAddress:private] => IN
            [city:PhpTwinfield\CustomerAddress:private] => Indore
            [postcode:PhpTwinfield\CustomerAddress:private] => 452001
            [telephone:PhpTwinfield\CustomerAddress:private] => 
            [fax:PhpTwinfield\CustomerAddress:private] => 
            [email:PhpTwinfield\CustomerAddress:private] => anand@comfisoft.com
            [field1:PhpTwinfield\CustomerAddress:private] => 
            [field2:PhpTwinfield\CustomerAddress:private] => lig
            [field4:PhpTwinfield\CustomerAddress:private] => 
            [field5:PhpTwinfield\CustomerAddress:private] => 
            [field6:PhpTwinfield\CustomerAddress:private] => 
        )

)

Solution

  • Try this it will work ;)

    function accessProtectedProperty($obj, $prop)
    {
        $reflection = new \ReflectionClass($obj);
        $property = $reflection->getProperty($prop);
        $property->setAccessible(true);
        return json_decode($property->getValue($obj));
    }