public function testGetRelPath() { $this->assertEquals('lib/XSExceptionTest.php', XSException::getRelPath(__FILE__)); $this->assertEquals('/phpunit.xml', XSException::getRelPath(dirname(__FILE__) . '/../phpunit.xml')); $this->assertEquals('../lib/XS.class.php', XSException::getRelPath('../../php/lib/XS.class.php')); XSException::getRelPath('/dev'); }
public function __construct($code, $message, $file, $line, $previous = null) { $this->_file = $file; $this->_line = $line; if (version_compare(PHP_VERSION, '5.3.0', '>=')) { parent::__construct($message, $code, $previous); } else { parent::__construct($message, $code); } }
$index->closeBuffer(); } } // end rebuild if ($rebuild !== null) { echo "完成重建索引 ...\n"; $index->endRebuild(); } else { echo "刷新索引提交 ...\n"; $index->flushIndex(); } } } catch (XSException $e) { // Exception $start = dirname(dirname(__FILE__)); $relative = XSException::getRelPath($start); $traceString = $e->getTraceAsString(); $traceString = str_replace(dirname(__FILE__) . '/', '', $traceString); $traceString = str_replace($start . ($relative === '' ? '/' : ''), $relative, $traceString); echo $e . "\n" . $traceString . "\n"; } // translate csv data function csvTransform($data) { static $fields = null; global $xs; /* @var $xs XS */ // init field set if (is_null($fields)) { // load default fields $fields = array_keys($xs->getScheme()->getAllFields());
} $content = file_get_contents($input . '/' . $entry); $content = strtr($content, $vars); if ($vars['@charset@'] !== 'UTF-8') { $content = XS::convert($content, $vars['@charset@'], 'UTF-8'); } file_put_contents($file, $content); } else { echo "正在复制 " . $entry . " ...\n"; $file = $output . '/' . $entry; if (is_dir($input . '/' . $entry)) { XSUtil::copyDir($input . '/' . $entry, $file); } else { if (file_exists($file)) { copy($file, $file . '.bak'); } copy($input . '/' . $entry, $file); } } } $dir->close(); echo "完成,请将 `{$output}` 目录转移到 web 可达目录,然后访问 search.php 即可。\n"; } catch (XSException $e) { // Exception $start = dirname(dirname(__FILE__)) . '/'; $relative = substr(XSException::getRelPath($start), 0, -1); $traceString = $e->getTraceAsString(); $traceString = str_replace(dirname(__FILE__) . '/', '', $traceString); $traceString = str_replace($start, $relative, $traceString); echo $e . "\n" . $traceString . "\n"; }