inital commit
[pharext/pharext.org] / app / Controller / Github / Repo.php
1 <?php
2
3 namespace app\Controller\Github;
4
5 use app\Controller\Github;
6
7 class Repo extends Github
8 {
9 function __invoke(array $args = null) {
10 extract($args);
11 if ($this->checkToken()) {
12 try {
13 $this->github->fetchRepo(
14 "$owner/$name",
15 [$this, "repoCallback"]
16 )->send();
17 } catch (\app\Github\Exception $exception) {
18 $this->app->getView()->addData(compact("exception", "owner", "name"));
19 }
20 $this->app->display("github/repo");
21 }
22 }
23
24 function repoCallback($repo, $links) {
25 $this->app->getView()->addData(compact("repo"));
26 settype($repo->tags, "object");
27 $this->github->fetchTags($repo->full_name, 1, $this->createTagsCallback($repo));
28 $this->github->fetchReleases($repo->full_name, 1, $this->createReleasesCallback($repo));
29 }
30
31 function createReleasesCallback($repo) {
32 return function($releases, $links) use($repo) {
33 foreach ($releases as $release) {
34 $tag = $release->tag_name;
35 settype($repo->tags->$tag, "object");
36 $repo->tags->$tag->release = $release;
37 }
38 };
39 }
40
41 function createTagsCallback($repo) {
42 return function($tags, $links) use ($repo) {
43 foreach ($tags as $tag) {
44 $name = $tag->name;
45 settype($repo->tags->$name, "object");
46 $repo->tags->$name->tag = $tag;
47 }
48 };
49 }
50 }