Repository navigation
Expand file tree
/
Copy pathObject.php
More file actions
94 lines (83 loc) · 3.14 KB
/
Copy pathObject.php
File metadata and controls
94 lines (83 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Github\Api;
/**
* Getting full versions of specific files and trees in your Git repositories.
*
* @link http://develop.github.com/p/object.html
* @author Thibault Duplessis <thibault.duplessis at gmail dot com>
* @license MIT License
*/
class Object extends Api
{
/**
* Get a listing of the root tree of a project by the username, repo, and tree SHA
* http://develop.github.com/p/object.html#trees
*
* @param string $username the username
* @param string $repo the repo
* @param string $treeSHA the tree sha
* @param boolean $resursive the recursive flag
* @return array root tree of the project
*/
public function showTree($username, $repo, $treeSHA, $recursive = false)
{
$url = 'repos/'.urlencode($username).'/'.urlencode($repo).'/git/trees/'.urlencode($treeSHA);
if ($recursive) {
$url .= '?recursive=1';
}
return $this->get($url);
}
/**
* Lists the data blobs of a tree by tree SHA
*
* @param string $username the username
* @param string $repo the repo
* @param string $treeSHA the tree sha
* @param string $path the path
* @return array data blobs of tree
*/
public function listBlobs($username, $repo, $treeSHA)
{
$tree = $this->showTree($username, $repo, $treeSHA, true);
if (isset($tree['tree'])) {
$blobs = array_filter($tree['tree'], function ($element) {
return 'blob' === $element['type'];
});
return $blobs;
}
}
/**
* Get the data about a blob by tree SHA and file path.
*
* @param string $username the username
* @param string $repo the repo
* @param string $treeSHA the tree sha
* @param string $path the path
* @return array data blob of tree and path
*/
public function showBlob($username, $repo, $treeSHA, $path)
{
$tree = $this->showTree($username, $repo, $treeSHA, true);
if (isset($tree['tree'])) {
$blobs = array_filter($tree['tree'], function ($element) use ($path) {
return $path === $element['path'];
});
return reset($blobs);
}
}
/**
* Returns the raw text content of the object.
*
* @param string $username the username
* @param string $repo the repo
* @param string $objectSHA the object sha can be either a blob SHA1, a tree SHA1 or a commit SHA1
* @return string raw text content of the blob, tree or commit object
*/
public function getRawData($username, $repo, $objectSHA)
{
$this->client->setHeaders(array('Accept: application/vnd.github.v3.raw'));
$response = $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/git/blobs/'.urlencode($objectSHA));
$this->client->clearHeaders();
return $response;
}
}