sscarpa / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
Apache License 2.0
0 stars 0 forks source link

"use_objects = true" results in only the outermost element to be returned as an object #31

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Set 'use_objects' => true in your config
2. Call e.g. $query = $plus->comments->listComments("INSERT_ACTIVITY_ID")

What is the expected output? What do you see instead?

$query is an Object of the type CommentFeed, that's OK. However, what I expect 
is that $query->items is an array of Comment objects. Instead, it is an array 
of arrays. So after all, only the main element is returned as an object, all 
children stay unchanged (although corresponding objects do exist!)

What version of the product are you using? On what operating system?

Version 0.4.5

Please provide any additional information below.

One possible solution for this issue which comes into my mind is overriding the 
apiModel constructor in the classes which may have children of another object 
type and convert them to objects afterwards.

Here is an example based on the CommentFeed object:

class CommentFeed extends apiModel {

  ...

  public function __construct() {
    parent::__construct(func_get_arg(0));

    foreach ($this->items as $key => $item) {
      $this->items[$key] = new Comment($item);
    }
  }

  ...
}

It's probably not best-practice, but it works. If the same change would be made 
to the other objects as well, we would have fully object-oriented results when 
'use_objects' is set to true.

Original issue reported on code.google.com by kaktus621@gmail.com on 5 Oct 2011 at 1:27

GoogleCodeExporter commented 8 years ago
use_objects isn't fully supported,  but is getting there.  You should now see 
full objects returned by the API in trunk as of r240.

Original comment by chirags@google.com on 10 Oct 2011 at 9:18

GoogleCodeExporter commented 8 years ago

Original comment by chirags@google.com on 11 Oct 2011 at 3:10