|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the League.csv library |
|
4
|
|
|
* |
|
5
|
|
|
* @license http://opensource.org/licenses/MIT |
|
6
|
|
|
* @link https://github.com/thephpleague/csv/ |
|
7
|
|
|
* @version 9.0.0 |
|
8
|
|
|
* @package League.csv |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
namespace League\Csv; |
|
14
|
|
|
|
|
15
|
|
|
use BadMethodCallException; |
|
16
|
|
|
use Countable; |
|
17
|
|
|
use JsonSerializable; |
|
18
|
|
|
use ReflectionClass; |
|
19
|
|
|
use ReflectionMethod; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* A class to interact with a CSV document without overriding it |
|
23
|
|
|
* |
|
24
|
|
|
* @package League.csv |
|
25
|
|
|
* @since 3.0.0 |
|
26
|
|
|
* |
|
27
|
|
|
* @method array fetchAll() |
|
28
|
|
|
* @method array fetchOne(int $offset = 0) |
|
29
|
|
|
* @method array fetchColumn(string|int $column_index = 0) |
|
30
|
|
|
* @method array fetchPairs(string|int $offset_index = 0, string|int $value_index = 1) |
|
31
|
|
|
* @method string toHTML(string $class_attr = 'table-csv-data') |
|
32
|
|
|
* @method DOMDocument toXML(string $root_name = 'csv', string $row_name = 'row', string $cell_name = 'cell') |
|
33
|
|
|
* @method array jsonSerialize() |
|
34
|
|
|
* @method int count() |
|
35
|
|
|
*/ |
|
36
|
|
|
class Reader extends AbstractCsv implements JsonSerializable, Countable |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @inheritdoc |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $stream_filter_mode = STREAM_FILTER_READ; |
|
42
|
|
|
|
|
43
|
159 |
|
/** |
|
44
|
|
|
* Returns the Record object |
|
45
|
159 |
|
* |
|
46
|
|
|
* @param Statement|null $stmt |
|
47
|
|
|
* |
|
48
|
|
|
* @return RecordSet |
|
49
|
|
|
*/ |
|
50
|
|
|
public function select(Statement $stmt = null) |
|
51
|
|
|
{ |
|
52
|
|
|
$stmt = $stmt ?: new Statement(); |
|
53
|
|
|
|
|
54
|
|
|
return new RecordSet($this, $stmt); |
|
55
|
|
|
} |
|
56
|
159 |
|
|
|
57
|
|
|
/** |
|
58
|
159 |
|
* @inheritdoc |
|
59
|
75 |
|
*/ |
|
60
|
|
|
public function __call($method, array $args) |
|
61
|
|
|
{ |
|
62
|
144 |
|
static $stmt; |
|
63
|
|
|
if (null === $stmt) { |
|
64
|
|
|
$stmt = new Statement(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
static $method_list; |
|
68
|
|
|
if (null === $method_list) { |
|
69
|
|
|
$method_list = array_flip(array_map(function (ReflectionMethod $method) { |
|
70
|
|
|
return $method->name; |
|
71
|
|
|
}, (new ReflectionClass(RecordSet::class))->getMethods(ReflectionMethod::IS_PUBLIC))); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
63 |
|
if (isset($method_list[$method])) { |
|
75
|
|
|
return call_user_func_array([new RecordSet($this, $stmt), $method], $args); |
|
76
|
63 |
|
} |
|
77
|
|
|
|
|
78
|
|
|
throw new BadMethodCallException(sprintf('Unknown method %s::%s', get_class($this), $method)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @inheritdoc |
|
83
|
|
|
*/ |
|
84
|
|
|
public function count() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->__call('count', []); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
9 |
|
/** |
|
90
|
|
|
* @inheritdoc |
|
91
|
9 |
|
*/ |
|
92
|
9 |
|
public function jsonSerialize() |
|
93
|
9 |
|
{ |
|
94
|
9 |
|
return $this->__call('jsonSerialize', []); |
|
95
|
6 |
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|