fix fork display that broke after ini parsing fix
[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         //we need raw parsing; https://bugs.php.net/bug.php?id=68347
14         $this->arConfig = parse_ini_file(
15             $this->repo->gitDir . '/config', true, INI_SCANNER_RAW
16         );
17     }
18
19     public function isFork()
20     {
21         return $this->getOrigin() !== null;
22     }
23
24     public function hasForks()
25     {
26         return count($this->getForks()) > 0;
27     }
28
29
30     public function getOrigin()
31     {
32         return $this->getRemote('origin');
33     }
34
35     /**
36      * @return Repository_Remote|null NULL if the remote does not exist, array
37      *                                with repository information otherwise
38      */
39     public function getRemote($name)
40     {
41         if (!isset($this->arConfig['remote "' . $name . '"'])) {
42             return null;
43         }
44         return new Repository_Remote($name, $this->arConfig['remote "' . $name . '"']);
45     }
46
47     public function getForks()
48     {
49         $arForks = array();
50         foreach ($this->arConfig as $name => $data) {
51             if (substr($name, 0, 13) != 'remote "fork-') {
52                 continue;
53             }
54             $arForks[substr($name, 8, -1)] = new Repository_Remote(
55                 substr($name, 8, -1), $data
56             );
57         }
58         return $arForks;
59     }
60 }
61 ?>