-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCsvFileReader.php
More file actions
54 lines (46 loc) · 1.21 KB
/
CsvFileReader.php
File metadata and controls
54 lines (46 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* CsvFileReader
*
* @author Ryuji AMANO <ryuji@ryus.co.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
// ε( v ゚ω゚) < 改行コードCR(Excel for Mac)への対応
App::uses('NetCommonsFile', 'Files.Utility');
/**
* Class CsvFileReader
*/
class CsvFileReader extends SplFileObject {
/**
* @var File 文字コード変換したテンポラリファイル
*/
protected $_tmpFile;
/**
* CsvFileReader constructor.
*
* @param string|File $filePath CSVファイルのFileインスタンスかファイルパス
*/
public function __construct($filePath) {
if (is_a($filePath, 'File')) {
$filePath = $filePath->path;
}
$tmp = NetCommonsFile::getTemporaryFileConvertSjisWin2Utf8($filePath);
$path = $tmp->path;
parent::__construct($path);
$this->setFlags(SplFileObject::READ_CSV);
}
/**
* valid SplFileObjectでCSVフィルを読ませると最終行の空配列で返るのでそれの抑止
*
* @return bool
*/
public function valid() {
$parentValid = parent::valid();
$var = parent::current();
if ($var === array(null)) {
return false;
}
return $parentValid;
}
}