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 return '/' . $this->repo->id . '/raw/' . $this->getFilename();
106 } else if ($type == 'tool') {
107 return '/' . $this->repo->id . '/tool/' . $option . '/' . $this->getFilename();
109 throw new Exception('Unknown type');
112 public function getMimeType()
114 $ext = $this->getExt();
115 if (!isset($GLOBALS['phorkie']['languages'][$ext])) {
118 return $GLOBALS['phorkie']['languages'][$ext]['mime'];
122 * @return array Array of Tool_Info objects
124 public function getToolInfos()
126 if ($this->repo->hash !== null) {
130 $tm = new Tool_Manager();
131 return $tm->getSuitable($this);
135 * Tells if the file contains textual content and is editable.
139 public function isText()
141 $ext = $this->getExt();
142 if (!isset($GLOBALS['phorkie']['languages'][$ext]['mime'])) {
146 $type = $GLOBALS['phorkie']['languages'][$ext]['mime'];
147 return substr($type, 0, 5) === 'text/';