1 | <?php |
||
7 | class CustomReader extends Reader |
||
8 | { |
||
9 | /** |
||
10 | * Should this reader ignore column headers that are null when importing? |
||
11 | * |
||
12 | * Sometimes Excel adds null headers to the end of a CSV and this can result in the |
||
13 | * CSV failing to parse. |
||
14 | * |
||
15 | * @var boolean |
||
16 | */ |
||
17 | protected $ignore_empty_headers = true; |
||
18 | |||
19 | /** |
||
20 | * Validates the array to be used by the fetchAssoc method |
||
21 | * |
||
22 | * @param array $keys |
||
23 | * |
||
24 | * @throws InvalidArgumentException If the submitted array fails the assertion |
||
25 | * |
||
26 | * @return array |
||
27 | */ |
||
28 | protected function validateKeys(array $keys) |
||
45 | |||
46 | /** |
||
47 | * Attempt to find the position of the last legitimate |
||
48 | * header column (a column that is not null and is the last |
||
49 | * item in the list that is not null). |
||
50 | * |
||
51 | * @param array $keys |
||
52 | * |
||
53 | * @return int |
||
54 | */ |
||
55 | protected function findLastHeaderPos(array $keys) |
||
89 | |||
90 | /** |
||
91 | * Get the ignore_empty_headers param |
||
92 | * |
||
93 | * @return boolean |
||
94 | */ |
||
95 | public function getIgnoreEmptyHeaders() |
||
99 | |||
100 | /** |
||
101 | * Set the ignore_empty_headers param |
||
102 | * |
||
103 | * @param boolean $ignore_empty_headers Ignore header keys that are blank? |
||
104 | * |
||
105 | * @return self |
||
106 | */ |
||
107 | public function setIgnoreEmptyHeaders(boolean $ignore_empty_headers) |
||
112 | } |
||
113 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: