2012-03-22 10 views
0

Facebook統合コンポーネントのデータをモデル化する最良の方法を探しています。この例では、Facebookのフォトアルバムを見ていきます。各ユーザーには1つまたは複数のアルバムがあり、1つまたは複数の写真が含まれます。アルバムと写真のためのデータ定義は、ここで見つけることができます: http://developers.facebook.com/docs/reference/api/album/http://developers.facebook.com/docs/reference/api/photo/このデータをPHPでどのようにモデル化できますか?

私の主な目標は、私は、コードの完全なことができます互換性をすべてのものを作るには特に興味を持って、できるだけ簡単にFacebookのグラフAPIを使用して作成することです。アルバムのために、例えば上記の文書で定義されているよう 最初は、私の考えは、まさに自分のクラスにデータをモデル化することでした:

 
/** 
* @property string $id The album ID 
* @property Profile $from The profile that created this album 
* @property string $name The title of the album 
* @property string $description The description of the album 
* @property string $location The location of the album 
* @property string $link A link to this album on Facebook 
* @property string $cover_photo The album cover photo ID 
* @property string $privacy The privacy settings for the album 
* @property int $count The number of photos in this album 
* @property string $type The type of the album: profile, mobile, wall, normal or album 
* @property string $created_time The time the photo album was initially created (ISO-8601 date-time) 
* @property array $likes The information about user likes 
* @property array $photos The Photos in this album 
* @property array $comments 
*/ 
class Album extends Graph 
{ 
    /** 
    * The album ID. 
    * @var string 
    */ 
    protected $id; 
    /** 
    * The profile that created this album. 
    * @var Profile 
    */ 
    protected $from; 

    /** 
    * The title of the album. 
    * @var string 
    */ 
    protected $name; 
    /** 
    * The description of the album. 
    * @var string 
    */ 
    protected $description; 
    /** 
    * The location of the album. 
    * @var string 
    */ 
    protected $location; 
    /** 
    * A link to this album on Facebook. 
    * @var string 
    */ 
    protected $link; 
    /** 
    * The album cover photo ID. 
    * Valid URL 
    * @var string 
    */ 
    protected $cover_photo; 
    /** 
    * The privacy settings for the album. 
    * @var string 
    */ 
    protected $privacy; 
    /** 
    * The number of photos in this album. 
    * @var string 
    */ 
    protected $count; 
    /** 
    * The type of the album: profile, mobile, wall, normal or album. 
    * @var string 
    */ 
    protected $type; 
    /** 
    * The time the photo album was initially created. 
    * ISO-8601 date-time 
    * @var string 
    */ 
    protected $created_time; 
    /** 
    * The last time the photo album was updated. 
    * ISO-8601 date-time 
    * @var string 
    */ 
    protected $updated_time; 
    /** 
    * The information about user likes 
    * @var array 
    */ 
    protected $likes; 
    /** 
    * The comments posted on this Album 
    * @var array 
    */ 
    protected $comments; 
    /** 
    * The Photos in this album 
    * @var array Graph\Album\Photo 
    */ 
    protected $photos; 

    /** 
    * Gets a specific album from the graph 
    * @param $id string 
    * @return Album 
    */ 
    public function getAlbum($id) 
    { 
     $this->setFromStdClass($this->getFromGraph("/{$id}")); 
     return $this; 
    } 

} 

この方法を使用して私はでき怠惰な負荷別のエントリ・ポイントからの写真のとき/場合、それらすべてがうまくいっていますが、コード補完をサポートする反復サポートされたオブジェクトを作成する方法がわかっていないので、要求から返される配列のコード補完を得ることはできません$this->photos[0]->...そこにすべてのプロパティを持つ時間の無駄、Facebookから戻ってきたstcClassがすでにあるので、データオブジェクトにそのデータを格納し、@propertyアノテーションとマジックメソッドを使用して、返されたstdClassからデータを取得します一つの特性で、同様に:私は私のモデルに変換するために戻っはstdClassを反復処理する必要がある、と一般的に同じように機能していないため

 
/** 
* @property string $id The album ID 
* @property Profile $from The profile that created this album 
* @property string $name The title of the album 
* @property string $description The description of the album 
* @property string $location The location of the album 
* @property string $link A link to this album on Facebook 
* @property string $cover_photo The album cover photo ID 
* @property string $privacy The privacy settings for the album 
* @property int $count The number of photos in this album 
* @property string $type The type of the album: profile, mobile, wall, normal or album 
* @property string $created_time The time the photo album was initially created (ISO-8601 date-time) 
* @property array $likes The information about user likes 
* @property array $photos The Photos in this album 
* @property array $comments 
*/ 
class Album extends Graph 
{ 
    protected $data; 

    public function __get($name) 
    { 
     $method = 'get' . ucfirst($name); 
     if (method_exists($this, $method)) { 
      return $this->{$method}(); 
     } 
     if (property_exists($this->data, $name)) { 
      return $this->data->{$name}; 
     } 
    } 
} 

これは、個々のメソッドを宣言してくれ、多くの時間を節約し、高速ですコード補完のために各プロパティを定義します。

HELP!

+0

まさに、ここで問題は何ですか? – JJJ

+0

質問は、私はこのデータをPHPでどのようにモデル化できますか?具体的には、コード補完を使ってPHPでどのようにモデル化できますか? – GeeH

答えて

1

はIDE /たPHPDocサポートに依存 - PHPStormは@propertyのSomePhotoCLassNameをサポートする必要があり、[]、そうでない場合は、あなたの配列に@var SomePhotoClassNameで終わる反復