From 4d3b1690a86631b4b1abc74dfa4c4e5bde8faf10 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 27 Mar 2012 07:50:58 +0200 Subject: listing all pastes works --- src/Phorkie/Repositories.php | 23 +++++++++++++++++++++++ src/Phorkie/Repository.php | 14 ++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'src') 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); -- cgit v1.2.3