00001 <?php
00002
00020
00021
00022
00023 class SearchFileParser {
00024
00026 var $filePath;
00027
00029 var $fp;
00030
00035 function SearchFileParser($filePath) {
00036 $this->filePath = $filePath;
00037 }
00038
00043 function getFilePath() {
00044 return $this->filePath;
00045 }
00046
00051 function setFilePath($filePath) {
00052 $this->filePath = $filePath;
00053 }
00054
00059 function open() {
00060 $this->fp = @fopen($this->filePath, 'rb');
00061 return $this->fp ? true : false;
00062 }
00063
00067 function close() {
00068 fclose($this->fp);
00069 }
00070
00075 function read() {
00076 if (!$this->fp || feof($this->fp)) {
00077 return false;
00078 }
00079 return $this->doRead();
00080 }
00081
00086 function doRead() {
00087 return fgets($this->fp, 4096);
00088 }
00089
00090
00091
00092
00093
00094
00100 function &fromFile(&$file) {
00101 $returner = &SearchFileParser::fromFileType($file->getFileType(), $file->getFilePath());
00102 return $returner;
00103 }
00104
00110 function &fromFileType($type, $path) {
00111 switch ($type) {
00112 case 'text/plain':
00113 $returner = &new SearchFileParser($path);
00114 break;
00115 case 'text/html':
00116 case 'text/xml':
00117 case 'application/xhtml':
00118 case 'application/xml':
00119 $returner = &new SearchHTMLParser($path);
00120 break;
00121 default:
00122 $returner = &new SearchHelperParser($type, $path);
00123 }
00124 return $returner;
00125 }
00126
00127 }
00128
00129 ?>