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 loadById($id)
47 if (!is_numeric($id)) {
48 throw new Exception_Input('Paste ID not numeric');
52 $repoDir = $GLOBALS['phorkie']['cfg']['repos'] . '/' . $this->id;
53 if (!is_dir($repoDir)) {
54 throw new Exception_NotFound('Paste not found');
56 $this->repoDir = $repoDir;
59 public function getVc()
61 return new \VersionControl_Git($this->repoDir);
65 * Loads the list of files in this repository
67 * @return File[] Array of files
69 public function getFiles()
71 $files = glob($this->repoDir . '/*');
73 foreach ($files as $path) {
74 $arFiles[] = new File($path, $this);
79 public function getFileByName($name)
81 $base = basename($name);
83 throw new Exception('No directories supported for now');
86 throw new Exception_Input('Empty file name given');
88 $path = $this->repoDir . '/' . $base;
89 if (!is_readable($path)) {
90 throw new Exception_Input('File does not exist');
92 return new File($path, $this);
95 public function hasFile($name)
98 $this->getFileByName($name);
99 } catch (Exception $e) {
105 public function getDescription()
107 if (!is_readable($this->repoDir . '/.git/description')) {
110 return file_get_contents($this->repoDir . '/.git/description');
113 public function setDescription($description)
115 file_put_contents($this->repoDir . '/.git/description', $description);
119 * Get a link to the repository
121 * @param string $type Link type. Supported are:
128 public function getLink($type)
130 if ($type == 'edit') {
131 return '/' . $this->id . '/edit';
132 } else if ($type == 'display') {
133 return '/' . $this->id;
134 } else if ($type == 'fork') {
135 return '/' . $this->id . '/fork';
137 throw new Exception('Unknown type');