first work on remote fork notifications with linkback (webmention/pingback)
[phorkie.git] / src / phorkie / Repository / ConnectionInfo.php
1 <?php
2 namespace phorkie;
3
4 class Repository_ConnectionInfo
5 {
6     protected $arConfig;
7     protected $repo;
8
9
10     public function __construct(Repository $repo)
11     {
12         $this->repo = $repo;
13         $this->arConfig = parse_ini_file($this->repo->gitDir . '/config', true);
14     }
15
16     public function isFork()
17     {
18         return $this->getOrigin() !== null;
19     }
20
21     public function hasForks()
22     {
23         return count($this->getForks()) > 0;
24     }
25
26
27     public function getOrigin()
28     {
29         return $this->getRemote('origin');
30     }
31
32     /**
33      * @return Repository_Remote|null NULL if the remote does not exist, array
34      *                                with repository information otherwise
35      */
36     public function getRemote($name)
37     {
38         if (!isset($this->arConfig['remote ' . $name])) {
39             return null;
40         }
41         return new Repository_Remote($name, $this->arConfig['remote ' . $name]);
42     }
43
44     public function getForks()
45     {
46         $arForks = array();
47         foreach ($this->arConfig as $name => $data) {
48             if (substr($name, 0, 12) != 'remote fork-') {
49                 continue;
50             }
51             $arForks[substr($name, 7)] = new Repository_Remote(
52                 substr($name, 7), $data
53             );
54         }
55         return $arForks;
56     }
57 }
58 ?>