Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
forks.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  * GitHub API Forks class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage GitHub
17  * @since 11.3
18  */
20 {
21  /**
22  * Method to fork a repository.
23  *
24  * @param string $user The name of the owner of the GitHub repository.
25  * @param string $repo The name of the GitHub repository.
26  * @param string $org The organization to fork the repo into. By default it is forked to the current user.
27  *
28  * @return object
29  *
30  * @since 11.4
31  * @throws DomainException
32  */
33  public function create($user, $repo, $org = '')
34  {
35  // Build the request path.
36  $path = '/repos/' . $user . '/' . $repo . '/forks';
37 
38  if (strlen($org) > 0)
39  {
40  $data = json_encode(
41  array('org' => $org)
42  );
43  }
44  else
45  {
46  $data = json_encode(array());
47  }
48 
49  // Send the request.
50  $response = $this->client->post($this->fetchUrl($path), $data);
51 
52  // Validate the response code.
53  if ($response->code != 202)
54  {
55  // Decode the error response and throw an exception.
56  $error = json_decode($response->body);
57  throw new DomainException($error->message, $response->code);
58  }
59 
60  return json_decode($response->body);
61  }
62 
63  /**
64  * Method to list forks for a repository.
65  *
66  * @param string $user The name of the owner of the GitHub repository.
67  * @param string $repo The name of the GitHub repository.
68  * @param integer $page Page to request
69  * @param integer $limit Number of results to return per page
70  *
71  * @return array
72  *
73  * @since 11.4
74  * @throws DomainException
75  */
76  public function getList($user, $repo, $page = 0, $limit = 0)
77  {
78  // Build the request path.
79  $path = '/repos/' . $user . '/' . $repo . '/forks';
80 
81  // Send the request.
82  $response = $this->client->get($this->fetchUrl($path, $page, $limit));
83 
84  // Validate the response code.
85  if ($response->code != 200)
86  {
87  // Decode the error response and throw an exception.
88  $error = json_decode($response->body);
89  throw new DomainException($error->message, $response->code);
90  }
91 
92  return json_decode($response->body);
93  }
94 }