Update jQuery from 1.12.4 to 3.7.1
[phorkie.git] / src / phorkie / Repository / Remote.php
1 <?php
2 namespace phorkie;
3
4 class Repository_Remote
5 {
6     protected $arConfig;
7     protected $name;
8
9     public function __construct($name, $arConfig)
10     {
11         $this->name = $name;
12         $this->arConfig = $arConfig;
13     }
14
15
16     public function getName()
17     {
18         return $this->name;
19     }
20
21     public function getTitle()
22     {
23         if (isset($this->arConfig['title'])) {
24             return $this->arConfig['title'];
25         }
26         if ($this->isLocal()) {
27             $local = $this->getLocalRepository();
28             if ($local !== null) {
29                 return $local->getTitle();
30             }
31             return 'deleted local paste';
32         }
33
34         return 'untitled repository';
35     }
36
37     public function getCloneURL()
38     {
39         if ($this->isLocal()) {
40             $local = $this->getLocalRepository();
41             if ($local !== null) {
42                 return $local->getCloneURL();
43             }
44         }
45
46         if (isset($this->arConfig['url'])) {
47             return $this->arConfig['url'];
48         }
49         return null;
50     }
51
52     public function getWebURL($full = false)
53     {
54         if (isset($this->arConfig['homepage'])) {
55             return $this->arConfig['homepage'];
56         }
57
58         if ($this->isLocal()) {
59             $local = $this->getLocalRepository();
60             if ($local !== null) {
61                 return $local->getLink('display', null, $full);
62             }
63         }
64
65         return null;
66     }
67
68     /**
69      * Tells you if this remote repository is a paste on the local server
70      *
71      * @return boolean True of false
72      */
73     public function isLocal()
74     {
75         return isset($this->arConfig['url'])
76             && $this->arConfig['url'][0] == '/';
77     }
78
79     /**
80      * If this remote is a local paste, then we'll get the repository object
81      * returned
82      *
83      * @return Repository Repository object or NULL
84      */
85     public function getLocalRepository()
86     {
87         if (!file_exists($this->arConfig['url'] . '/config')) {
88             return null;
89         }
90         $dir = basename($this->arConfig['url']);
91         if (substr($dir, -4) != '.git') {
92             //phorks are bare repositories "123.git"
93             return null;
94         }
95         $repo = new Repository();
96         $repo->loadById(substr($dir, 0, -4));
97         return $repo;
98     }
99
100 }
101
102 ?>