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/File.php | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/Phorkie/File.php (limited to 'src/Phorkie/File.php') diff --git a/src/Phorkie/File.php b/src/Phorkie/File.php new file mode 100644 index 0000000..f12d837 --- /dev/null +++ b/src/Phorkie/File.php @@ -0,0 +1,69 @@ +path = $path; + $this->repo = $repo; + } + + /** + * Get filename relative to the repository path + * + * @return string + */ + public function getFilename() + { + return basename($this->path); + } + + /** + * Returns the type of the file, as used internally by Phorkie + * + * @return string + */ + public function getType() + { + return substr($this->path, strrpos($this->path, '.') + 1); + } + + public function getContent() + { + return file_get_contents($this->path); + } + + /** + * Get a link to the file + * + * @param string $type Link type. Supported are: + * - "raw" + * - "display" + * + * @return string + */ + public function getLink($type) + { + if ($type == 'raw') { + return '/' . $this->repo->id . '/raw/' . $this->getFilename(); + } + throw new Exception('Unknown type'); + } +} + +?> \ No newline at end of file -- cgit v1.2.3