Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
github.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage GitHub
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 GitHub server instance.
14  *
15  * @property-read JGithubGists $gists GitHub API object for gists.
16  * @property-read JGithubIssues $issues GitHub API object for issues.
17  * @property-read JGithubPulls $pulls GitHub API object for pulls.
18  * @property-read JGithubRefs $refs GitHub API object for referencess.
19  * @property-read JGithubForks $forks GitHub API object for forks.
20  * @property-read JGithubCommits $commits GitHub API object for commits.
21  * @property-read JGithubMilestones $milestones GitHub API object for commits.
22  * @property-read JGithubStatuses $statuses GitHub API object for commits.
23  * @property-read JGithubAccount $account GitHub API object for account references.
24  * @property-read JGithubHooks $hooks GitHub API object for hooks.
25  * @property-read JGithubUsers $users GitHub API object for users.
26  * @property-read JGithubMeta $meta GitHub API object for meta.
27  *
28  * @package Joomla.Platform
29  * @subpackage GitHub
30  * @since 11.3
31  */
32 class JGithub
33 {
34  /**
35  * @var JRegistry Options for the GitHub object.
36  * @since 11.3
37  */
38  protected $options;
39 
40  /**
41  * @var JGithubHttp The HTTP client object to use in sending HTTP requests.
42  * @since 11.3
43  */
44  protected $client;
45 
46  /**
47  * @var JGithubGists GitHub API object for gists.
48  * @since 11.3
49  */
50  protected $gists;
51 
52  /**
53  * @var JGithubIssues GitHub API object for issues.
54  * @since 11.3
55  */
56  protected $issues;
57 
58  /**
59  * @var JGithubPulls GitHub API object for pulls.
60  * @since 11.3
61  */
62  protected $pulls;
63 
64  /**
65  * @var JGithubRefs GitHub API object for referencess.
66  * @since 11.3
67  */
68  protected $refs;
69 
70  /**
71  * @var JGithubForks GitHub API object for forks.
72  * @since 11.3
73  */
74  protected $forks;
75 
76  /**
77  * @var JGithubCommits GitHub API object for commits.
78  * @since 12.1
79  */
80  protected $commits;
81 
82  /**
83  * @var JGithubMilestones GitHub API object for milestones.
84  * @since 12.3
85  */
86  protected $milestones;
87 
88  /**
89  * @var JGithubStatuses GitHub API object for statuses.
90  * @since 12.3
91  */
92  protected $statuses;
93 
94  /**
95  * @var JGithubAccount GitHub API object for account references.
96  * @since 12.3
97  */
98  protected $account;
99 
100  /**
101  * @var JGithubHooks GitHub API object for hooks.
102  * @since 12.3
103  */
104  protected $hooks;
105 
106  /**
107  * @var JGithubUsers GitHub API object for users.
108  * @since 12.4
109  */
110  protected $users;
111 
112  /**
113  * @var JGithubMeta GitHub API object for meta.
114  * @since 13.1
115  */
116  protected $meta;
117 
118  /**
119  * Constructor.
120  *
121  * @param JRegistry $options GitHub options object.
122  * @param JGithubHttp $client The HTTP client object.
123  *
124  * @since 11.3
125  */
126  public function __construct(JRegistry $options = null, JGithubHttp $client = null)
127  {
128  $this->options = isset($options) ? $options : new JRegistry;
129  $this->client = isset($client) ? $client : new JGithubHttp($this->options);
130 
131  // Setup the default API url if not already set.
132  $this->options->def('api.url', 'https://api.github.com');
133  }
134 
135  /**
136  * Magic method to lazily create API objects
137  *
138  * @param string $name Name of property to retrieve
139  *
140  * @return JGithubObject GitHub API object (gists, issues, pulls, etc).
141  *
142  * @since 11.3
143  * @throws InvalidArgumentException
144  */
145  public function __get($name)
146  {
147  $class = 'JGithub' . ucfirst($name);
148 
149  if (class_exists($class))
150  {
151  if (false == isset($this->$name))
152  {
153  $this->$name = new $class($this->options, $this->client);
154  }
155 
156  return $this->$name;
157  }
158 
159  throw new InvalidArgumentException(sprintf('Argument %s produced an invalid class name: %s', $name, $class));
160  }
161 
162  /**
163  * Get an option from the JGitHub instance.
164  *
165  * @param string $key The name of the option to get.
166  *
167  * @return mixed The option value.
168  *
169  * @since 11.3
170  */
171  public function getOption($key)
172  {
173  return $this->options->get($key);
174  }
175 
176  /**
177  * Set an option for the JGitHub instance.
178  *
179  * @param string $key The name of the option to set.
180  * @param mixed $value The option value to set.
181  *
182  * @return JGitHub This object for method chaining.
183  *
184  * @since 11.3
185  */
186  public function setOption($key, $value)
187  {
188  $this->options->set($key, $value);
189 
190  return $this;
191  }
192 }