Version 1
[yaffs-website] / vendor / php-instagram-api / php-instagram-api / Instagram / Core / BaseObjectAbstract.php
1 <?php
2
3 /**
4 * Instagram PHP
5 * @author Galen Grover <galenjr@gmail.com>
6 * @license http://opensource.org/licenses/mit-license.php The MIT License
7 */
8
9 namespace Instagram\Core;
10
11 /**
12  * Base object that all objects extend from
13  *
14  * Provides core functionality
15  */
16 abstract class BaseObjectAbstract {
17
18     /**
19      * Object data
20      * 
21      * @var StdClass
22      * @access protected
23      */
24     protected $data;
25
26     /**
27      * Proxy object that does all the API heavy lifting
28      * 
29      * @var \Instagram\Core\Proxy
30      * @access protected
31      */
32     protected $proxy = null;
33
34     /**
35      * Get the ID returned from the API
36      *
37      * @return string 
38      * @access public
39      */
40     public function getId() {
41         return $this->data->id;
42     }
43
44     /**
45      * Get the API ID
46      *
47      * Some API objects don't have IDs (tags, some locations )
48      * Those objects define their own getId() methods to return a psuedo ID
49      * Tags = tag name, ID-less locations return null
50      * 
51      * @return string Returns the ID
52      * @access public
53      */
54     public function getApiId() {
55         return $this->getId();
56     }
57
58     /**
59      * Constructor
60      * 
61      * @param StdClass $data Object's data
62      * @param \Instagram\Core\Proxy $proxy Object's proxy
63      * @access public
64      */
65     public function __construct( $data, \Instagram\Core\Proxy $proxy = null ) {
66         $this->setData( $data );
67         $this->proxy = $proxy;
68     }
69
70     /**
71      * Set the object's data
72      * 
73      * @param StdClass $data Object data
74      * @access public
75      */
76     public function setData( $data ) {
77         $this->data = $data;
78     }
79
80     /**
81      * Get the object's data
82      * 
83      * @return Stdclass Returns the object's data
84      * @access public
85      */
86     public function getData() {
87         return $this->data;
88     }
89
90     /**
91      * Magic method to get data
92      *
93      * This may be removed in future versions
94      * 
95      * @param string $var Variable ot get from the data
96      * @return mixed Returns the variable or null
97      * @access public
98      */
99     public function __get( $var ) {
100         return isset( $this->data->$var ) ? $this->data->$var : null;
101     }
102
103     /**
104      * Set the object's proxy
105      * 
106      * @param \Instagram\Core\Proxy $proxy Proxy object
107      * @access public
108      */
109     public function setProxy( \Instagram\Core\Proxy $proxy ) {
110         $this->proxy = $proxy;
111     }
112
113 }