diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2012-11-21 22:34:24 +0100 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2012-11-21 22:34:24 +0100 |
| commit | ba158e3ed03dec10e6654b0b0dd3710504bdf04d (patch) | |
| tree | 80112971f0e3b6d5d1f1ec4ef28f2208b7ff1680 /src/phorkie/Repository/Remote.php | |
| parent | d63a7b14a6e1140fe5aa0610b1490f69b3494623 (diff) | |
| download | phorkie-ba158e3ed03dec10e6654b0b0dd3710504bdf04d.tar.gz phorkie-ba158e3ed03dec10e6654b0b0dd3710504bdf04d.zip | |
first work on Fork origin display; works for local forks
Diffstat (limited to 'src/phorkie/Repository/Remote.php')
| -rw-r--r-- | src/phorkie/Repository/Remote.php | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/phorkie/Repository/Remote.php b/src/phorkie/Repository/Remote.php new file mode 100644 index 0000000..4f5034c --- /dev/null +++ b/src/phorkie/Repository/Remote.php @@ -0,0 +1,94 @@ +<?php +namespace phorkie; + +class Repository_Remote +{ + protected $arConfig; + protected $name; + + public function __construct($name, $arConfig) + { + $this->name = $name; + $this->arConfig = $arConfig; + } + + + public function getTitle() + { + if (isset($this->arConfig['title'])) { + return $this->arConfig['title']; + } + if ($this->isLocal()) { + $local = $this->getLocalRepository(); + if ($local !== null) { + return $local->getTitle(); + } + return 'deleted local paste'; + } + + return 'untitled repository'; + } + + public function getCloneURL() + { + if ($this->isLocal()) { + $local = $this->getLocalRepository(); + if ($local !== null) { + return $local->getCloneURL(); + } + } + + return $this->arConfig['url']; + } + + public function getWebURL() + { + if (isset($this->arConfig['homepage'])) { + return $this->arConfig['homepage']; + } + + if ($this->isLocal()) { + $local = $this->getLocalRepository(); + if ($local !== null) { + return $local->getLink('display'); + } + } + + return null; + } + + /** + * Tells you if this remote repository is a paste on the local server + * + * @return boolean True of false + */ + public function isLocal() + { + return isset($this->arConfig['url']) + && $this->arConfig['url']{0} == '/'; + } + + /** + * If this remote is a local paste, then we'll get the repository object + * returned + * + * @return Repository Repository object or NULL + */ + public function getLocalRepository() + { + if (!file_exists($this->arConfig['url'] . '/config')) { + return null; + } + $dir = basename($this->arConfig['url']); + if (substr($dir, -4) != '.git') { + //phorks are bare repositories "123.git" + return null; + } + $repo = new Repository(); + $repo->loadById(substr($dir, 0, -4)); + return $repo; + } + +} + +?> |
