I feel a bit silly, but I have no clue how to parse the objects that Google returns from their API in PHP, can someone shine a light on it?
So for instance, if I request:
print_r($job->getState());
I get this:
Google\Cloud\Scheduler\V1\HttpTarget Object
(
[uri:Google\Cloud\Scheduler\V1\HttpTarget:private] => http://example.com/cron-check.php
[http_method:Google\Cloud\Scheduler\V1\HttpTarget:private] => 1
[headers:Google\Cloud\Scheduler\V1\HttpTarget:private] => Google\Protobuf\Internal\MapField Object...
So how in the world do I get the uri value out of this object?
Googling the Object you're receiving in response, I found the source code for it:
https://github.com/googleapis/google-cloud-php/blob/master/Scheduler/src/V1/HttpTarget.php
Looking at this, there appears to be a simple getter method for the URI property. Try:
$job->getState()->getUri();
Related
I am trying to parse this complex SOAP response:
But I get lost with the namespaces and children methods...any idea how to extract the highlighted data?
I tried this:
$xml->children( $ns['S'] )->Body->children( $ns['ns7'] )->Answer->children( $ns['ns3'] );
but it doesn't work
You should use a WSDL to PHP generator which will ease you the request construction and response handling. Indeed, you'll handle PHP object with getters/setters which is better in my point of view.
I can only suggest you to try the PackageGenerator project.
I've never used SOAP before, and I'm getting this when I print out an array. Could someone tell me whether it's working, or not? I'm not sure what the Resource id stands for and I couldn't find an answer..
$this->client = new SoapClient("https://api.cvent.com/soap/V200611.ASMX?WSDL", array('trace' => true, 'exceptions' => true));
echo '<pre>';print_r($this->client);echo '</pre>';
SoapClient Object
(
[trace] => 1
[_soap_version] => 1
[sdl] => Resource id #251
)
If anyone could help me out, that'd be great.
I'm glad you solved your issue.
I went ahead anyway to figure out what sdl is and how to use it.
I checked the SOAP extension source code and it looks like the resource represents the parsed and interpreted WSDL which is used internally for near enough all the SoapClient methods to lookup and return definitions data.
#L379 le_sdl = zend_register_list_destructors_ex(delete_sdl_res, NULL, "SOAP SDL", module_number);
le_sdl is of type sdlPtr (service definition language pointer? ) and is referenced throughout.
https://github.com/php/php-src/blob/7bbc85f16ac7b54b3cdbadc787518aed33369b7e/ext/soap/soap.c
I have no idea why we can view this resource as a public property SOAP_GLOBAL(sdl) as it doesn't look like it can be read by any PHP function.
Its not in the list of defined resource types and the Soap documentation clearly says that the extension doesn't have any defined.
This extension has no resource types defined.
Fatal error: Call to a member function get() on a non-object on
pr($transaction->invoice->get());
I am getting a weird message. I know for sure the method is there, and is available to use, and even double checked before using it. What's wrong here?
pr(get_class_methods($transaction->invoice));
Array
(
[0] => __construct
[1] => get
[2] => __toString
[3] => getHref
[4] => setHref
[5] => _get
)
Update:
var_dump(is_object($transaction->invoice)); evaluated as bool(true)
None of the methods work. I'm so confused! I think this is one of those edge cases. I'm using Recurly library.
Update
Looks like some objects coming back were un-instantiating themselves. That's weird. I didn't know PHP does this.
What you experience here is Magic. As Magic is so hard to understand, it's even harder to debug. Expect a large chunk of that Recurly PHP library to be based on Magic.
Looks like some objects coming back were un-instantiating themselves. That's weird. I didn't know PHP does this.
It's not PHP, but the library. It makes use of magic getters and setters and other magic stuff for the properties. They must have been driven by some wizard being so much in love with magic. Don't you feel enchanted yet?
Best way to get above the Magic is that you install yourself a step debugger like Xdebug and then set a breakpoint and inspect the values directly. All common PHP IDEs have support for xdebug remote debugging (even this is called remote debugging, it works on your local development machine, too).
I'm trying to use Zend_Soap_Client to communicate with an ASP.net web service. Here's my client call:
$client = new Zend_Soap_Client(null, array(
'location' => 'http://example.com/service.asmx',
'uri' => 'http://example.com/'
));
$user = new UserDetail();
$result = $client->UserDetails($user);
However this always gives me the error:
System.NullReferenceException: Object reference not set to an instance of an object. at Service.UserDetails(UserDetail UserDetail)
some googling revealed that this is quite a common problem. The most common solution seemed to be to pass the parameters as an array, so I tried:
$result = $client->UserDetails(array('UserDetail' => $user));
but this gave the same error. I also tried passing the params as a stdClass object, nesting the array in another with 'params' as the key, and a few other things but the error is always the same.
I have the ASP code for the web service itself, the relevant method is:
public Result UserDetails(UserDetail UserDetail) {
[some stuff]
Hashtable ht = new Hashtable();
ht = UserDetail.GenerateData();
}
the error is caused by the GenerateData() call.
I assume the UserDetails method is getting null instead of my object as the parameter, but I'm not sure how I should be calling the method, or how I can debug this further. The majority of the Zend_Soap_Client examples I've found seem to be using WSDL, which this service is not; not sure if that is relevant. Any help appreciated!
I eventually solved this with:
$userDetails = new UserDetails();
$userDetails->UserDetail = $user;
$client->UserDetails($userDetails);
it seems ASP.net expects (and returns) params to be nested in an object/array with the same name as the method being called.
If you have any possibility to change the asp.net code I'd suggest you try an implementation of the method UserDetails without parameters just to make sure that code isn't broken.
I would then create a consumer-method in asp.net, debug the http-request and see how the userdetail-object is serialized/broken down in array form. Then it's "just" a matter of creating a similar http request from php.
It took me a while to get soap configured in php. Now I'm just trying to learn about it. I'm using the web service here to learn:
http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=19
It says the WSDL is here:
http://www.webservicex.net/stockquote.asmx?wsdl
and this is my code:
$client = new SoapClient('http://www.webservicex.net/stockquote.asmx?wsdl');
$result = $client->getQuote("AAPL");
echo $result;
I'm getting an error saying "Object of class stdClass could not be converted to string". Now I realize that $result is an object, and I'm wondering how do I access data that the server populated? I tried to understand the WSDL but I'm getting nowhere. Is it supposed to be something like:
$result->price
? (That doesn't work by the way...)
Ideas?
When curious about datatypes from the soapserver, use the SoapClient->__getTypes() & SoapClient->__getFunctions() methods
If you return is still not clear, var_dump() your return and examine it.