@@ -20,6 +20,22 @@ public function __construct()
2020 $this->mParser = new PHPParser_Parser(new PHPParser_Lexer);
2121 }
2222
23+ public function setMFile($file) {
24+ if(empty($file)) {
25+ throw new PHPCtagsException('No File specified.');
26+ }
27+
28+ if(!file_exists($file)) {
29+ throw new PHPCtagsException('Warning: cannot open source file "' . $file . '" : No such file');
30+ }
31+
32+ if(!is_readable($file)) {
33+ throw new PHPCtagsException('Warning: cannot open source file "' . $file . '" : File is not readable');
34+ }
35+
36+ $this->mFile = realpath($file);
37+ }
38+
2339 public static function getMKinds()
2440 {
2541 return self::$mKinds;
@@ -253,15 +269,19 @@ public function export($file, $options)
253269 continue;
254270 }
255271
256- //@todo Check for existence
257- $this->mFile = (string) $filename;
272+ $this->setMFile((string) $filename);
258273 $structs += $this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE);
259274 }
260275 } else {
261- //@todo Check for existence
262- $this->mFile = $file;
276+ $this->setMFile($file);
263277 $structs += $this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE);
264278 }
265279 return $this->render($structs, $options);
266280 }
267281}
282+
283+ class PHPCtagsException extends Exception {
284+ public function __toString() {
285+ return "PHPCtags: {$this->message}\n";
286+ }
287+ }
0 commit comments