7 * Path to the file, relative to repository work directory
14 * Repository this file belongs to
21 * Commit revision this file is at
25 public function __construct($path, Repository $repo = null)
32 * Get filename relative to the repository path
36 public function getFilename()
42 * Return the full path to the file
46 public function getFullPath()
48 return $this->repo->workDir . '/' . $this->path;
52 * Get file extension without dot
56 public function getExt()
58 return substr($this->path, strrpos($this->path, '.') + 1);
61 public function getContent()
63 if ($this->repo->hash) {
64 return $this->repo->getVc()->getCommand('show')
65 ->addArgument($this->repo->hash . ':' . $this->path)
69 return file_get_contents($this->getFullPath());
72 public function getRenderedContent(Tool_Result $res = null)
74 $ext = $this->getExt();
75 $class = '\\phorkie\\Renderer_Unknown';
77 if (isset($GLOBALS['phorkie']['languages'][$ext]['renderer'])) {
78 $class = $GLOBALS['phorkie']['languages'][$ext]['renderer'];
79 } else if (isset($GLOBALS['phorkie']['languages'][$ext]['mime'])) {
80 $type = $GLOBALS['phorkie']['languages'][$ext]['mime'];
81 if (substr($type, 0, 5) == 'text/') {
82 $class = '\\phorkie\\Renderer_Geshi';
83 } else if (substr($type, 0, 6) == 'image/') {
84 $class = '\\phorkie\\Renderer_Image';
89 return $rend->toHtml($this, $res);
93 * Get a link to the file
95 * @param string $type Link type. Supported are:
98 * @param string $option
102 public function getLink($type, $option = null)
104 if ($type == 'raw') {
105 if ($this->repo->hash === null) {
106 return '/' . $this->repo->id . '/raw/' . $this->getFilename();
108 return '/' . $this->repo->id . '/rev-raw/' . $this->repo->hash
109 . '/' . $this->getFilename();
111 } else if ($type == 'tool') {
112 return '/' . $this->repo->id . '/tool/' . $option . '/' . $this->getFilename();
114 throw new Exception('Unknown type');
117 public function getMimeType()
119 $ext = $this->getExt();
120 if (!isset($GLOBALS['phorkie']['languages'][$ext])) {
123 return $GLOBALS['phorkie']['languages'][$ext]['mime'];
127 * @return array Array of Tool_Info objects
129 public function getToolInfos()
131 if ($this->repo->hash !== null) {
135 $tm = new Tool_Manager();
136 return $tm->getSuitable($this);
140 * Tells if the file contains textual content and is editable.
144 public function isText()
146 $ext = $this->getExt();
147 if (!isset($GLOBALS['phorkie']['languages'][$ext]['mime'])) {
151 $type = $GLOBALS['phorkie']['languages'][$ext]['mime'];
152 return substr($type, 0, 5) === 'text/';