XSCsvDataSource
CSV 数据源
可在文件开头指定字段(必须是有效字段), 否则将默认按照
XS 项目字段顺序填充
属性明细
public $invalidLines;
方法明细
protected void getDataList()
|
源码: sdk/php/util/XSDataSource.class.php#L392 (
显示)
protected function getDataList()
{
if (($item = fgetcsv($this->fd, 0, $this->delim)) === false) {
if ($this->inCli) {
echo "INFO: reach end of file or error occured, total lines: " . $this->line . "\n";
}
return false;
}
$this->line++;
if (count($item) === 1 && is_null($item[0])) {
if ($this->inCli) {
echo "WARNING: invalid csv line #" . $this->line . "\n";
}
$this->invalidLines++;
return $this->getDataList();
}
return array($item);
}
源码: sdk/php/util/XSDataSource.class.php#L368 (
显示)
protected function init()
{
$file = $this->arg;
if (empty($file) && $this->inCli) {
echo "WARNING: input file not specified, read data from <STDIN>\n";
$file = 'php://stdin';
}
if (!($this->fd = fopen($file, 'r'))) {
throw new XSException("Can not open input file: '$file'");
}
$this->line = 0;
if (isset($_SERVER['XS_CSV_DELIMITER'])) {
$this->delim = $_SERVER['XS_CSV_DELIMITER'];
}
}
留下一条评论吧!
请到论坛 登录 后刷新本页面!