summaryrefslogtreecommitdiff
path: root/src/phorkie/Repository/ConnectionInfo.php
blob: f6a7a40697fef6b52d10cb5ff748654a22fac76c (plain)
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
<?php
namespace phorkie;

class Repository_ConnectionInfo
{
    protected $arConfig;
    protected $repo;


    public function __construct(Repository $repo)
    {
        $this->repo = $repo;
        //we need raw parsing; https://bugs.php.net/bug.php?id=68347
        $this->arConfig = parse_ini_file(
            $this->repo->gitDir . '/config', true, INI_SCANNER_RAW
        );
    }

    public function isFork()
    {
        return $this->getOrigin() !== null;
    }

    public function hasForks()
    {
        return count($this->getForks()) > 0;
    }


    public function getOrigin()
    {
        return $this->getRemote('origin');
    }

    /**
     * @return Repository_Remote|null NULL if the remote does not exist, array
     *                                with repository information otherwise
     */
    public function getRemote($name)
    {
        if (!isset($this->arConfig['remote "' . $name . '"'])) {
            return null;
        }
        return new Repository_Remote($name, $this->arConfig['remote "' . $name . '"']);
    }

    public function getForks()
    {
        $arForks = array();
        foreach ($this->arConfig as $name => $data) {
            if (substr($name, 0, 13) != 'remote "fork-') {
                continue;
            }
            $arForks[substr($name, 8, -1)] = new Repository_Remote(
                substr($name, 8, -1), $data
            );
        }
        return $arForks;
    }
}
?>