8 * Repository ID (number in repositories directory)
15 * Full path to the git repository
22 * Load Repository data from GET-Request
26 * @throws Exception When something is wrong
28 public function loadFromRequest()
30 if (!isset($_GET['id'])) {
31 throw new Exception_Input('Paste ID missing');
33 if (!is_numeric($_GET['id'])) {
34 throw new Exception_Input('Paste ID not numeric');
36 $this->id = (int)$_GET['id'];
38 $repoDir = $GLOBALS['phorkie']['cfg']['repos'] . '/' . $this->id;
39 if (!is_dir($repoDir)) {
40 throw new Exception_NotFound('Paste not found');
42 $this->repoDir = $repoDir;
45 public function getVc()
47 return new \VersionControl_Git($this->repoDir);
51 * Loads the list of files in this repository
53 * @return File[] Array of files
55 public function getFiles()
57 $files = glob($this->repoDir . '/*');
59 foreach ($files as $path) {
60 $arFiles[] = new File($path, $this);
65 public function getFileByName($name)
67 $base = basename($name);
69 throw new Exception('No directories supported for now');
71 $path = $this->repoDir . '/' . $base;
72 if (!is_readable($path)) {
73 throw new Exception_Input('File does not exist');
75 return new File($path, $this);
78 public function getDescription()
80 if (!is_readable($this->repoDir . '/.git/description')) {
83 return file_get_contents($this->repoDir . '/.git/description');
87 * Get a link to the repository
89 * @param string $type Link type. Supported are:
96 public function getLink($type)
98 if ($type == 'edit') {
99 return '/' . $this->id . '/edit';
100 } else if ($type == 'display') {
101 return '/' . $this->id;
102 } else if ($type == 'fork') {
103 return '/' . $this->id . '/fork';
105 throw new Exception('Unknown type');