Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
twitter.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Twitter
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die();
11 
12 /**
13  * Joomla Platform class for interacting with a Twitter API instance.
14  *
15  * @package Joomla.Platform
16  * @subpackage Twitter
17  * @since 12.3
18  */
19 class JTwitter
20 {
21  /**
22  * @var JRegistry Options for the GitHub object.
23  * @since 12.3
24  */
25  protected $options;
26 
27  /**
28  * @var JHttp The HTTP client object to use in sending HTTP requests.
29  * @since 12.3
30  */
31  protected $client;
32 
33  /**
34  * @var JTwitterOAuth The OAuth client.
35  * @since 12.3
36  */
37  protected $oauth;
38 
39  /**
40  * @var JTwitterFriends Twitter API object for friends.
41  * @since 12.3
42  */
43  protected $friends;
44 
45  /**
46  * @var JTwitterUsers Twitter API object for users.
47  * @since 12.3
48  */
49  protected $users;
50 
51  /**
52  * @var JTwitterHelp Twitter API object for help.
53  * @since 12.3
54  */
55  protected $help;
56 
57  /**
58  * @var JTwitterStatuses Twitter API object for statuses.
59  * @since 12.3
60  */
61  protected $statuses;
62 
63  /**
64  * @var JTwitterSearch Twitter API object for search.
65  * @since 12.3
66  */
67  protected $search;
68 
69  /**
70  * @var JTwitterFavorites Twitter API object for favorites.
71  * @since 12.3
72  */
73  protected $favorites;
74 
75  /**
76  * @var JTwitterDirectMessages Twitter API object for direct messages.
77  * @since 12.3
78  */
79  protected $directMessages;
80 
81  /**
82  * @var JTwitterLists Twitter API object for lists.
83  * @since 12.3
84  */
85  protected $lists;
86 
87  /**
88  * @var JTwitterPlaces Twitter API object for places & geo.
89  * @since 12.3
90  */
91  protected $places;
92 
93  /**
94  * @var JTwitterTrends Twitter API object for trends.
95  * @since 12.3
96  */
97  protected $trends;
98 
99  /**
100  * @var JTwitterBlock Twitter API object for block.
101  * @since 12.3
102  */
103  protected $block;
104 
105  /**
106  * @var JTwitterProfile Twitter API object for profile.
107  * @since 12.3
108  */
109  protected $profile;
110 
111  /**
112  * Constructor.
113  *
114  * @param JTwitterOauth $oauth The oauth client.
115  * @param JRegistry $options Twitter options object.
116  * @param JHttp $client The HTTP client object.
117  *
118  * @since 12.3
119  */
120  public function __construct(JTwitterOAuth $oauth = null, JRegistry $options = null, JHttp $client = null)
121  {
122  $this->oauth = $oauth;
123  $this->options = isset($options) ? $options : new JRegistry;
124  $this->client = isset($client) ? $client : new JHttp($this->options);
125 
126  // Setup the default API url if not already set.
127  $this->options->def('api.url', 'https://api.twitter.com/1.1');
128  }
129 
130  /**
131  * Magic method to lazily create API objects
132  *
133  * @param string $name Name of property to retrieve
134  *
135  * @return JTwitterObject Twitter API object (statuses, users, favorites, etc.).
136  *
137  * @since 12.3
138  * @throws InvalidArgumentException
139  */
140  public function __get($name)
141  {
142  $class = 'JTwitter' . ucfirst($name);
143 
144  if (class_exists($class))
145  {
146  if (false == isset($this->$name))
147  {
148  $this->$name = new $class($this->options, $this->client, $this->oauth);
149  }
150 
151  return $this->$name;
152  }
153 
154  throw new InvalidArgumentException(sprintf('Argument %s produced an invalid class name: %s', $name, $class));
155  }
156 
157  /**
158  * Get an option from the JTwitter instance.
159  *
160  * @param string $key The name of the option to get.
161  *
162  * @return mixed The option value.
163  *
164  * @since 12.3
165  */
166  public function getOption($key)
167  {
168  return $this->options->get($key);
169  }
170 
171  /**
172  * Set an option for the JTwitter instance.
173  *
174  * @param string $key The name of the option to set.
175  * @param mixed $value The option value to set.
176  *
177  * @return JTwitter This object for method chaining.
178  *
179  * @since 12.3
180  */
181  public function setOption($key, $value)
182  {
183  $this->options->set($key, $value);
184 
185  return $this;
186  }
187 }