diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Phorkie/Repositories.php | 23 | ||||
| -rw-r--r-- | src/Phorkie/Repository.php | 14 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/Phorkie/Repositories.php b/src/Phorkie/Repositories.php index 3afe8c5..eeaec34 100644 --- a/src/Phorkie/Repositories.php +++ b/src/Phorkie/Repositories.php @@ -27,6 +27,29 @@ class Repositories return $r; } + /** + * Get a list of repository objects + * + * @param integer $page Page number, beginning with 0 + * @param integer $perPage Number of repositories per page + * + * @return array Array of Repositories + */ + public function getList($page = 0, $perPage = 10) + { + chdir($this->reposDir); + $dirs = glob('*', GLOB_ONLYDIR); + sort($dirs, SORT_NUMERIC); + + $some = array_slice($dirs, $page * $perPage, $perPage); + $repos = array(); + foreach ($some as $oneDir) { + $r = new Repository(); + $r->loadById($oneDir); + $repos[] = $r; + } + return $repos; + } } ?> diff --git a/src/Phorkie/Repository.php b/src/Phorkie/Repository.php index f23db7e..aeccc72 100644 --- a/src/Phorkie/Repository.php +++ b/src/Phorkie/Repository.php @@ -42,6 +42,20 @@ class Repository $this->repoDir = $repoDir; } + public function loadById($id) + { + if (!is_numeric($id)) { + throw new Exception_Input('Paste ID not numeric'); + } + $this->id = (int)$id; + + $repoDir = $GLOBALS['phorkie']['cfg']['repos'] . '/' . $this->id; + if (!is_dir($repoDir)) { + throw new Exception_NotFound('Paste not found'); + } + $this->repoDir = $repoDir; + } + public function getVc() { return new \VersionControl_Git($this->repoDir); |
