From 5f427dd38c8d47711ea73015076bb390761e05dd Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 26 Mar 2012 08:05:46 +0200 Subject: use repository and file classes --- src/Phorkie/Repository.php | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/Phorkie/Repository.php (limited to 'src/Phorkie/Repository.php') diff --git a/src/Phorkie/Repository.php b/src/Phorkie/Repository.php new file mode 100644 index 0000000..ae01f6c --- /dev/null +++ b/src/Phorkie/Repository.php @@ -0,0 +1,86 @@ +id = (int)$_GET['id']; + + $repoDir = $GLOBALS['phorkie']['cfg']['repos'] . '/' . $this->id; + if (!is_dir($repoDir)) { + throw new Exception_NotFound('Paste not found'); + } + $this->repoDir = $repoDir; + } + + /** + * Loads the list of files in this repository + * + * @return File[] Array of files + */ + public function getFiles() + { + $files = glob($this->repoDir . '/*'); + $arFiles = array(); + foreach ($files as $path) { + $arFiles[] = new File($path, $this); + } + return $arFiles; + } + + public function getDescription() + { + return file_get_contents($this->repoDir . '/.git/description'); + } + + /** + * Get a link to the repository + * + * @param string $type Link type. Supported are: + * - "edit" + * - "display" + * + * @return string + */ + public function getLink($type) + { + if ($type == 'edit') { + return '/' . $this->id . '/edit'; + } else if ($type == 'display') { + return '/' . $this->id; + } + throw new Exception('Unknown type'); + } + +} + +?> -- cgit v1.2.3